This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathledstripe.ino
169 lines (154 loc) · 4.89 KB
/
ledstripe.ino
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define LED_PIN 2
// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 5
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
void setup() {
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
}
void loop() {
// Lifecycle demo
showGreeting();
delay(100);
showIsAwake();
delay(3000);
showNeedsWatering();
delay(3000);
showThanksForWatering();
delay(2000);
showGoodbye();
delay(2000);
}
void showGreeting() {
// fade from off to green
for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
for (int j = 0; j <101; j++) {
strip.setPixelColor(i, 25, j, 0);
strip.show();
delay(10);
}
for (int j = 0; j <26; j++) {
strip.setPixelColor(i, j, 100, 0);
strip.show();
}
}
// wink twice
showWink();
}
void showGoodbye() {
// fade from green to off
for (int i = strip.numPixels() -1; i > -1 ; i--) {
for (int j = 100; j > -1; j--) {
strip.setPixelColor(i, 0, j, 0);
strip.show();
delay(10);
}
}
strip.clear();
}
void showIsAwake() {
// show static green
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 25, 100, 0);
}
strip.show();
}
void showNeedsWatering() {
// fade from greenish to reddish color
// decrease green color
for (int i = strip.numPixels() -1; i > -1 ; i--) {
for (int j = 100; j > 19; j--) {
strip.setPixelColor(i, 25, j, 0);
strip.show();
delay(2*i + i);
}
}
// increase red color
for (int i = 0; i < strip.numPixels(); i++) {
for (int j = 25; j < 81; j++) {
strip.setPixelColor(i, j, 20, 0);
strip.show();
delay(10);
}
}
}
void showThanksForWatering() {
// perform awesome animations...
rainbow(10); // rainbow demo already looks smooth and elegant
showWink();
delay(2000);
showWink();
delay(3000);
rainbow(5);
// turn off
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 0, 0, 0);
}
strip.show();
// return to green awake display
showIsAwake();
}
void showWink() {
// "wink" by turning off the light for a short time twice
// remember current color for each pixel
uint32_t colors[strip.numPixels()];
for (int i = 0; i < strip.numPixels(); i++) {
colors[i] = strip.getPixelColor(i);
}
// wink twice
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 0, 0, 0);
}
strip.show();
delay(60);
for (int i = 0; i < strip.numPixels(); i++){
strip.setPixelColor(i, colors[i]);
}
strip.show();
delay(120);
for (int i = 0; i < strip.numPixels(); i++){
strip.setPixelColor(i, 0, 0, 0);
}
strip.show();
delay(60);
for (int i = 0; i < strip.numPixels(); i++){
strip.setPixelColor(i, colors[i]);
}
strip.show();
}
// Some functions of our own for creating animated effects -----------------
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {
// Hue of first pixel runs 5 complete loops through the color wheel.
// Color wheel has a range of 65536 but it's OK if we roll over, so
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
// means we'll make 5*65536/256 = 1280 passes through this outer loop:
for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) {
for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
// Offset pixel hue by an amount to make one full revolution of the
// color wheel (range of 65536) along the length of the strip
// (strip.numPixels() steps):
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
// optionally add saturation and value (brightness) (each 0 to 255).
// Here we're using just the single-argument hue variant. The result
// is passed through strip.gamma32() to provide 'truer' colors
// before assigning to each pixel:
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}