-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSketchArduino.ino
More file actions
139 lines (125 loc) · 5.63 KB
/
SketchArduino.ino
File metadata and controls
139 lines (125 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define NUM_LEDS 32
#define PIN 6
#define BRIGHTNESS 20
#define BUTTON_PREVIOUS 13
#define BUTTON_NEXT 12
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
bool oldStatePrevious = HIGH;
bool oldStateNext = HIGH;
int showType = 0;
void setup() {
pinMode(BUTTON_PREVIOUS, INPUT_PULLUP);
pinMode(BUTTON_NEXT, INPUT_PULLUP);
strip.setBrightness(BRIGHTNESS);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Get current button state.
bool newStatePrevious = digitalRead(BUTTON_PREVIOUS);
bool newStateNext = digitalRead(BUTTON_NEXT);
// Check if state changed from high to low (button press).
if (newStateNext == LOW && oldStateNext == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newStateNext = digitalRead(BUTTON_NEXT);
if (newStateNext == LOW) {
showType++;
if (showType > 2)
showType=0;
startShow(showType);
}
}
// Check if state changed from high to low (button press).
if (newStatePrevious == LOW && oldStatePrevious == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newStatePrevious = digitalRead(BUTTON_PREVIOUS);
if (newStatePrevious == LOW) {
showType--;
if (showType < 0)
showType=3;
startShow(showType);
}
}
// Set the last button state to the old state.
oldStateNext = newStateNext;
oldStatePrevious = newStatePrevious;
}
void startShow(int i) {
switch(i){
case 0: rainbowStrip();
break;
case 1: middleFill(strip.Color(0, 255, 0), 100);
break;
case 2: sideFill(strip.Color(255, 0, 0), 100);
break;
}
}
void rainbowStrip() {
int i = 0;
while(i<NUM_LEDS*4) {
strip.setPixelColor(i%NUM_LEDS, strip.Color(255, 255, 255)); //change RGB color value here
strip.setPixelColor((i+1)%NUM_LEDS, strip.Color(255, 5, 180)); //change RGB color value here
strip.setPixelColor((i+2)%NUM_LEDS, strip.Color(255, 0, 0)); //change RGB color value here
strip.setPixelColor((i+3)%NUM_LEDS, strip.Color(255, 150, 0)); //change RGB color value here
strip.setPixelColor((i+4)%NUM_LEDS, strip.Color(255, 255, 5)); //change RGB color value here
strip.setPixelColor((i+5)%NUM_LEDS, strip.Color(0, 255, 0)); //change RGB color value here
strip.setPixelColor((i+6)%NUM_LEDS, strip.Color(0, 0, 255)); //change RGB color value here
strip.setPixelColor((i+7)%NUM_LEDS, strip.Color(135, 10, 215)); //change RGB color value here
strip.setPixelColor((i+8)%NUM_LEDS, strip.Color(255, 255, 255)); //change RGB color value here
strip.setPixelColor((i+9)%NUM_LEDS, strip.Color(255, 5, 180)); //change RGB color value here
strip.setPixelColor((i+10)%NUM_LEDS, strip.Color(255, 0, 0)); //change RGB color value here
strip.setPixelColor((i+11)%NUM_LEDS, strip.Color(255, 150, 0)); //change RGB color value here
strip.setPixelColor((i+12)%NUM_LEDS, strip.Color(255, 255, 5)); //change RGB color value here
strip.setPixelColor((i+13)%NUM_LEDS, strip.Color(0, 255, 0)); //change RGB color value here
strip.setPixelColor((i+14)%NUM_LEDS, strip.Color(0, 0, 255)); //change RGB color value here
strip.setPixelColor((i+15)%NUM_LEDS, strip.Color(135, 10, 215)); //change RGB color value here
strip.setPixelColor((i+16)%NUM_LEDS, strip.Color(255, 255, 255)); //change RGB color value here
strip.setPixelColor((i+17)%NUM_LEDS, strip.Color(255, 5, 180)); //change RGB color value here
strip.setPixelColor((i+18)%NUM_LEDS, strip.Color(255, 0, 0)); //change RGB color value here
strip.setPixelColor((i+19)%NUM_LEDS, strip.Color(255, 150, 0)); //change RGB color value here
strip.setPixelColor((i+20)%NUM_LEDS, strip.Color(255, 255, 5)); //change RGB color value here
strip.setPixelColor((i+21)%NUM_LEDS, strip.Color(0, 255, 0)); //change RGB color value here
strip.setPixelColor((i+22)%NUM_LEDS, strip.Color(0, 0, 255)); //change RGB color value here
strip.setPixelColor((i+23)%NUM_LEDS, strip.Color(135, 10, 215)); //change RGB color value here
strip.setPixelColor((i+24)%NUM_LEDS, strip.Color(255, 255, 255)); //change RGB color value here
strip.setPixelColor((i+25)%NUM_LEDS, strip.Color(255, 5, 180)); //change RGB color value here
strip.setPixelColor((i+26)%NUM_LEDS, strip.Color(255, 0, 0)); //change RGB color value here
strip.setPixelColor((i+27)%NUM_LEDS, strip.Color(255, 150, 0)); //change RGB color value here
strip.setPixelColor((i+28)%NUM_LEDS, strip.Color(255, 255, 5)); //change RGB color value here
strip.setPixelColor((i+29)%NUM_LEDS, strip.Color(0, 255, 0)); //change RGB color value here
strip.setPixelColor((i+30)%NUM_LEDS, strip.Color(0, 0, 255)); //change RGB color value here
strip.setPixelColor((i+31)%NUM_LEDS, strip.Color(135, 10, 215)); //change RGB color value here
i++;
strip.show();
delay(75);
}
}
// Light up the strip starting from the middle
void middleFill(uint32_t c, uint8_t wait) {
clearStrip();
delay(wait);
for(uint16_t i=0; i<(strip.numPixels()/2); i++) { // start from the middle, lighting an LED on each side
strip.setPixelColor(strip.numPixels()/2 + i, c);
strip.setPixelColor(strip.numPixels()/2 - i, c);
strip.show();
delay(wait);
}
strip.setPixelColor(0, c);
strip.show();
delay(wait);
for(uint16_t i=0; i<(strip.numPixels()/2); i++) { // reverse
strip.setPixelColor(i, strip.Color(0, 0, 0));
strip.setPixelColor(strip.numPixels() - i, strip.Color(0, 0, 0));
strip.show();
delay(wait);
}
clearStrip();
}