Skip to content

Commit 338d401

Browse files
authored
Add files via upload
1 parent c603ce5 commit 338d401

File tree

1 file changed

+384
-0
lines changed

1 file changed

+384
-0
lines changed
Lines changed: 384 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,384 @@
1+
#include <FastLED.h>
2+
3+
#define LED_PIN 7
4+
#define NUM_LEDS 60
5+
6+
CRGB leds[NUM_LEDS];
7+
8+
char incoming_command = '0';
9+
long ran = random(NUM_LEDS);
10+
long de = random(1000);
11+
12+
int l = 1;
13+
boolean setting = 0;
14+
15+
int bright = 50;
16+
17+
void check_for_input() {
18+
if (Serial.available() > 0) {
19+
// read the incoming byte:
20+
incoming_command = Serial.read();
21+
22+
// say what you got:
23+
//Serial.print("I received: ");
24+
//Serial.println(incoming_command);
25+
}
26+
}
27+
28+
void setup() {
29+
Serial.begin(9600);
30+
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
31+
FastLED.setBrightness(bright);
32+
randomSeed(analogRead(0));
33+
}
34+
35+
void loop() {
36+
int L = 60-l;
37+
int M;
38+
check_for_input();
39+
if (incoming_command == 'G'){
40+
Serial.println("Switching: ");
41+
setting = !setting;
42+
Serial.println(setting);
43+
delay(1000);
44+
}
45+
// if (setting == 0){
46+
// M = 60;
47+
// }
48+
// else if (setting == 1){
49+
// M = L;
50+
// }
51+
else if (incoming_command == '1'){
52+
Serial.println("RED");
53+
for (int i = 0; i <= L; i++) {
54+
leds[i] = CRGB (255,0,0);
55+
FastLED.show();
56+
delay(40);
57+
}
58+
}
59+
else if (incoming_command == 'F'){
60+
for (int i = 60; i >= 0; i--) {
61+
leds[i] = CRGB (0,0,0);
62+
FastLED.show();
63+
delay(40);
64+
}
65+
leds[60] = CRGB (255,0,0);
66+
FastLED.show();
67+
pl:
68+
check_for_input();
69+
Serial.println(l);
70+
//while((incoming_command != 'A') || (incoming_command != 'B') || (incoming_command != 'D')){
71+
// check_for_input();
72+
//}
73+
if (incoming_command == 'B'){
74+
if (l < 60){
75+
l++;
76+
}
77+
}
78+
if (incoming_command == 'D'){
79+
if (l > 0){
80+
l--;
81+
}
82+
}
83+
//for (int i = l; i >= 0; i--) {
84+
// leds[i] = CRGB (0,0,0);
85+
// FastLED.show();
86+
//}
87+
leds[l] = CRGB (255,0,0);
88+
FastLED.show();
89+
if (incoming_command != 'A'){
90+
goto pl;
91+
}
92+
for (int i = 59; i >= 0; i--) {
93+
leds[i] = CRGB (0,0,0);
94+
FastLED.show();
95+
delay(40);
96+
}
97+
}
98+
else if (incoming_command == '0'){
99+
Serial.println("WHITE");
100+
for (int i = 0; i <= L; i++) {/////////////////////////////
101+
leds[i] = CRGB (255,255,255);
102+
FastLED.show();
103+
delay(40);
104+
}
105+
}
106+
else if (incoming_command == '2'){
107+
Serial.println("ORANGE");
108+
for (int i = 0; i <= L; i++) {
109+
leds[i] = CRGB (255,128,0);
110+
FastLED.show();
111+
delay(40);
112+
}
113+
}
114+
else if (incoming_command == '3'){
115+
Serial.println("YELLOW");
116+
for (int i = 0; i <= L; i++) {
117+
leds[i] = CRGB (255,255,0);
118+
FastLED.show();
119+
delay(40);
120+
}
121+
}
122+
else if (incoming_command == '4'){
123+
Serial.println("GREEN");
124+
for (int i = 0; i <= L; i++) {
125+
leds[i] = CRGB (0,255,0);
126+
FastLED.show();
127+
delay(40);
128+
}
129+
}
130+
else if (incoming_command == '5'){
131+
Serial.println("TEAL");
132+
for (int i = 0; i <= L; i++) {
133+
leds[i] = CRGB (0,255,255);
134+
FastLED.show();
135+
delay(40);
136+
}
137+
}
138+
else if (incoming_command == '6'){
139+
Serial.println("BLUE");
140+
for (int i = 0; i <= L; i++) {
141+
leds[i] = CRGB (0,0,255);
142+
FastLED.show();
143+
delay(40);
144+
}
145+
}
146+
else if (incoming_command == '7'){
147+
Serial.println("PINK");
148+
for (int i = 0; i <= L; i++) {
149+
leds[i] = CRGB (255,51,255);
150+
FastLED.show();
151+
delay(40);
152+
}
153+
}
154+
else if (incoming_command == '8'){
155+
Serial.println("PURPLE");
156+
for (int i = 0; i <= L; i++) {
157+
leds[i] = CRGB (127,0,255);
158+
FastLED.show();
159+
delay(40);
160+
}
161+
}
162+
else if (incoming_command == '9'){
163+
for (int i = 0; i <= L; i++) {
164+
leds[i] = CRGB (128,128,128);
165+
FastLED.show();
166+
delay(40);
167+
}
168+
}
169+
else if (incoming_command == 'E'){
170+
sp:
171+
rainbowCycle(10);
172+
if (incoming_command != 'A'){
173+
goto sp;
174+
}
175+
}
176+
else if (incoming_command == 'B'){
177+
if (bright < 100){
178+
bright++;
179+
}
180+
FastLED.setBrightness(bright);
181+
}
182+
else if (incoming_command == 'D'){
183+
if (bright > 0){
184+
bright--;
185+
}
186+
FastLED.setBrightness(bright);
187+
}
188+
else if (incoming_command == 'A' && setting == 0){
189+
for (int i = 60; i >= 0; i--) {
190+
leds[i] = CRGB (0,0,0);
191+
FastLED.show();
192+
delay(40);
193+
}
194+
}
195+
else if (incoming_command == 'A' && setting == 1){
196+
for (int i = L; i >= 0; i--) {
197+
leds[i] = CRGB (0,0,0);
198+
FastLED.show();
199+
delay(40);
200+
}
201+
}
202+
else if (incoming_command == 'C'){
203+
for (int i = 0; i <= 60; i++) {
204+
leds[i] = CRGB (0,0,0);
205+
FastLED.show();
206+
delay(20);
207+
}
208+
st:
209+
long ran = random(60);
210+
long de = random(2000);
211+
long d = random(50);
212+
leds[ran] = CRGB(255,255,255);
213+
FastLED.show();
214+
delay(d);
215+
leds[ran] = CRGB(0,0,0);
216+
FastLED.show();
217+
delay(de);
218+
check_for_input();
219+
if (incoming_command != 'A'){
220+
goto st;
221+
}
222+
}
223+
else if (incoming_command == 'Q' && setting == 1){
224+
Serial.println("WHITE2");
225+
for (int i = L; i <= 60; i++) {
226+
leds[i] = CRGB (255,255,255);
227+
FastLED.show();
228+
delay(40);
229+
}
230+
}
231+
else if (incoming_command == 'R' && setting == 1){
232+
Serial.println("OFF2");
233+
for (int i = 60; i >= L; i--) {
234+
leds[i] = CRGB (0,0,0);
235+
FastLED.show();
236+
delay(40);
237+
}
238+
}
239+
else if (incoming_command == 'H' && setting == 1){
240+
for (int i = L; i <= 60; i++) {
241+
leds[i] = CRGB (255,0,0);
242+
FastLED.show();
243+
delay(40);
244+
}
245+
}
246+
else if (incoming_command == 'I' && setting == 1){
247+
for (int i = L; i <= 60; i++) {
248+
leds[i] = CRGB (255,128,0);
249+
FastLED.show();
250+
delay(40);
251+
}
252+
}
253+
else if (incoming_command == 'J' && setting == 1){
254+
for (int i = L; i <= 60; i++) {
255+
leds[i] = CRGB (255,255,0);
256+
FastLED.show();
257+
delay(40);
258+
}
259+
}
260+
else if (incoming_command == 'K' && setting == 1){
261+
for (int i = L; i <= 60; i++) {
262+
leds[i] = CRGB (0,255,0);
263+
FastLED.show();
264+
delay(40);
265+
}
266+
}
267+
else if (incoming_command == 'L' && setting == 1){
268+
for (int i = L; i <= 60; i++) {
269+
leds[i] = CRGB (0,255,255);
270+
FastLED.show();
271+
delay(40);
272+
}
273+
}
274+
else if (incoming_command == 'M' && setting == 1){
275+
for (int i = L; i <= 60; i++) {
276+
leds[i] = CRGB (0,0,255);
277+
FastLED.show();
278+
delay(40);
279+
}
280+
}
281+
else if (incoming_command == 'N' && setting == 1){
282+
for (int i = L; i <= 60; i++) {
283+
leds[i] = CRGB (255,51,255);
284+
FastLED.show();
285+
delay(40);
286+
}
287+
}
288+
else if (incoming_command == 'O' && setting == 1){
289+
for (int i = L; i <= 60; i++) {
290+
leds[i] = CRGB (127,0,255);
291+
FastLED.show();
292+
delay(40);
293+
}
294+
}
295+
else if (incoming_command == 'P' && setting == 1){
296+
for (int i = L; i <= 60; i++) {
297+
leds[i] = CRGB (128,128,128);
298+
FastLED.show();
299+
delay(40);
300+
}
301+
}
302+
}
303+
304+
305+
306+
307+
308+
309+
void rainbowCycle(int SpeedDelay) {
310+
byte *c;
311+
uint16_t i, j;
312+
313+
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
314+
for(i=0; i< NUM_LEDS; i++) {
315+
c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
316+
setPixel(i, *c, *(c+1), *(c+2));
317+
}
318+
showStrip();
319+
delay(SpeedDelay);
320+
check_for_input();
321+
if (incoming_command == 'A'){
322+
goto ne;
323+
}
324+
}
325+
ne:
326+
delay(2);
327+
}
328+
329+
byte * Wheel(byte WheelPos) {
330+
static byte c[3];
331+
332+
if(WheelPos < 85) {
333+
c[0]=WheelPos * 3;
334+
c[1]=255 - WheelPos * 3;
335+
c[2]=0;
336+
} else if(WheelPos < 170) {
337+
WheelPos -= 85;
338+
c[0]=255 - WheelPos * 3;
339+
c[1]=0;
340+
c[2]=WheelPos * 3;
341+
} else {
342+
WheelPos -= 170;
343+
c[0]=0;
344+
c[1]=WheelPos * 3;
345+
c[2]=255 - WheelPos * 3;
346+
}
347+
348+
return c;
349+
}
350+
351+
352+
353+
354+
355+
void showStrip() {
356+
#ifdef ADAFRUIT_NEOPIXEL_H
357+
// NeoPixel
358+
strip.show();
359+
#endif
360+
#ifndef ADAFRUIT_NEOPIXEL_H
361+
// FastLED
362+
FastLED.show();
363+
#endif
364+
}
365+
366+
void setPixel(int Pixel, byte red, byte green, byte blue) {
367+
#ifdef ADAFRUIT_NEOPIXEL_H
368+
// NeoPixel
369+
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
370+
#endif
371+
#ifndef ADAFRUIT_NEOPIXEL_H
372+
// FastLED
373+
leds[Pixel].r = red;
374+
leds[Pixel].g = green;
375+
leds[Pixel].b = blue;
376+
#endif
377+
}
378+
379+
void setAll(byte red, byte green, byte blue) {
380+
for(int i = 0; i < NUM_LEDS; i++ ) {
381+
setPixel(i, red, green, blue);
382+
}
383+
showStrip();
384+
}

0 commit comments

Comments
 (0)