Skip to content

Commit 5ed964e

Browse files
committed
initial
1 parent 272affb commit 5ed964e

File tree

6 files changed

+228
-0
lines changed

6 files changed

+228
-0
lines changed

Diff for: animation.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef ANIMATION_H
2+
#define ANIMATION_H
3+
4+
#include "ledarray.h"
5+
6+
class Animation
7+
{
8+
/*
9+
** Class that stores all of the animations that are being used in an LED array
10+
** Purpose: Loop only calls Animation.animate: a function that essentailly loops the
11+
**
12+
*/
13+
14+
public:
15+
virtual void step(LEDArray *ledarray) = 0;
16+
};
17+
18+
#endif

Diff for: ledarray.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <FastLED.h>
2+
#include "ledarray.h"
3+
4+
LEDArray::LEDArray(struct CRGB *_leds, long _NUM_LEDS){
5+
leds=_leds;
6+
num_leds=_NUM_LEDS;
7+
}
8+
9+
void LEDArray::init_noise(){
10+
for(int i=0; i<num_leds; i++){
11+
leds[i] = CHSV(random(255),255,255);
12+
}
13+
}
14+
15+
void LEDArray::init_rainbow(){
16+
fill_gradient(leds,num_leds,CHSV(0,255,255),CHSV(1,255,255),LONGEST_HUES);
17+
}
18+
19+
void LEDArray::init_single(){
20+
fill_solid(leds,num_leds,CHSV(0,0,0));
21+
leds[1]=CRGB(255,255,255);
22+
}
23+
24+
void LEDArray::rotate(){
25+
CRGB led0=leds[0];
26+
for(int i=0; i<num_leds-1; i++){
27+
leds[i] = leds[i+1];
28+
}
29+
30+
leds[num_leds-1]=led0;
31+
}

Diff for: ledarray.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef LEDARRAY_H
2+
#define LEDARRAY_H
3+
4+
class LEDArray
5+
{
6+
public:
7+
LEDArray(struct CRGB *_leds, long _NUM_LEDS);
8+
9+
// initialization utilities
10+
void init_noise();
11+
void init_rainbow();
12+
void init_single();
13+
// animation utilities
14+
void rotate();
15+
16+
//private:
17+
long num_leds;
18+
struct CRGB *leds;
19+
20+
};
21+
22+
#endif

Diff for: light_arduino.ino

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <FastLED.h>
2+
#include <PacketSerial.h>
3+
#define LED_TYPE NEOPIXEL
4+
#define COLOR_ORDER RGB
5+
#define framerate 500
6+
//#define COLOR_CORRECTION CRGB(255,172,240)
7+
#define BRIGHTNESS 125
8+
#define NUM_STRIPS 5
9+
#define NUM_LEDS_PER_STRIP 240
10+
#define NUM_LEDS 1118
11+
CRGB leds[NUM_LEDS];
12+
13+
#include "ledarray.h"
14+
#include "animation.h"
15+
#include "noise.h"
16+
17+
#define NUM_ANIMATIONS 1
18+
Animation * current_animation;
19+
Animation *(*list[NUM_ANIMATIONS])(LEDArray * ledarray);
20+
LEDArray *ledarray;
21+
22+
void setup() {
23+
24+
// power-up sanity delay
25+
pinMode(12, INPUT);
26+
27+
//delay( 3000 );
28+
29+
// tell FastLED about the LEDs
30+
FastLED.addLeds<NEOPIXEL, 2>(leds, 0*NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
31+
FastLED.addLeds<NEOPIXEL, 3>(leds, 1*NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
32+
FastLED.addLeds<NEOPIXEL, 6>(leds, 2*NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
33+
FastLED.addLeds<NEOPIXEL, 4>(leds, 3*NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
34+
FastLED.addLeds<NEOPIXEL, 5>(leds, 4*NUM_LEDS_PER_STRIP, 158);
35+
36+
// set master brightness control
37+
FastLED.setBrightness(BRIGHTNESS);
38+
//fill_solid(leds,NUM_LEDS,CHSV(128,255,128));
39+
FastLED.show();
40+
ledarray=new LEDArray(leds,NUM_LEDS);
41+
42+
list[0] = &noise_factory;
43+
//list[1] = &foobar_factory;
44+
45+
current_animation = list[0](ledarray);
46+
47+
}
48+
49+
// loop is called repeatedly forever
50+
void loop()
51+
{
52+
current_animation->step(ledarray);
53+
/*if(digitalRead(12)==HIGH){
54+
fill_solid(leds,NUM_LEDS,CHSV(64,255,128));
55+
56+
} else {
57+
fill_solid(leds,NUM_LEDS,CHSV(192,255,128));
58+
}
59+
60+
FastLED.show(); */
61+
}

Diff for: noise.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef NOISE_H
2+
#define NOISE_H
3+
4+
#include "animation.h"
5+
6+
class Noise : public Animation {
7+
public:
8+
Noise(LEDArray *ledarray)
9+
{
10+
ledarray->init_single();
11+
FastLED.show();
12+
13+
}
14+
15+
void step(LEDArray *ledarray)
16+
{
17+
ledarray->rotate();
18+
FastLED.show();
19+
}
20+
};
21+
22+
Animation * noise_factory(LEDArray *ledarray) {
23+
return new Noise(ledarray);
24+
}
25+
26+
#endif

Diff for: serial.h

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
void sendString(String string){
3+
int len=string.length()+1;
4+
uint8_t tmp[len];
5+
string.getBytes(tmp,len);
6+
serial.send(tmp,len-1);
7+
}
8+
9+
serial.setPacketHandler(&onPacket);
10+
serial.begin(115200);
11+
//sendString(START);
12+
13+
14+
// This is our packet callback.
15+
// The buffer is delivered already decoded.
16+
void onPacket(const uint8_t* buffer, size_t size)
17+
{
18+
19+
if(size==0){
20+
serialMode=true;
21+
sendString("ok");
22+
//fill_solid(leds,NUM_LEDS,CHSV(0,255,255));
23+
} else {
24+
serialMode=false;
25+
26+
27+
uint8_t cmd=buffer[0];
28+
if (cmd==1){
29+
sleep_mult=buffer[1];
30+
}
31+
32+
if (cmd==5){
33+
clut[buffer[1]]=CHSV(buffer[2],buffer[3],buffer[4]);
34+
sendString("set clut");
35+
} else {
36+
sendString("unknown cmd");
37+
}
38+
39+
//animate();
40+
}
41+
/*
42+
if(mode==1){
43+
sendString("full fill");
44+
fill_solid(leds,NUM_LEDS,CHSV(buffer[1],buffer[2],buffer[3]));
45+
46+
47+
} else if(mode==2){
48+
sendString("gradient fill");
49+
fill_gradient(leds,NUM_LEDS,CHSV(buffer[1],buffer[2],buffer[3]),CHSV(buffer[4],buffer[5],buffer[6]),LONGEST_HUES);
50+
} else if(mode==3){
51+
sendString("repeat pattern");
52+
53+
int num_colors=(size-1)/3;
54+
for(int i = 0; i < NUM_LEDS; i++) {
55+
int color_num=i%num_colors;
56+
leds[i] = CHSV(buffer[3*color_num+1],buffer[3*color_num+2],buffer[3*color_num+3]);
57+
}
58+
59+
60+
} else if(mode==4){
61+
sendString("block fill");
62+
long start=buffer[1]<<8 | buffer[2];
63+
long num=buffer[3]<<8 | buffer[4];
64+
fill_solid(leds+start,num,CHSV(buffer[5],buffer[6],buffer[7]));
65+
} else {
66+
sendString("unknown mode");
67+
}
68+
*/
69+
//FastLED.show();
70+
}

0 commit comments

Comments
 (0)