-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlight-stream.ino
More file actions
89 lines (73 loc) · 2.64 KB
/
Copy pathlight-stream.ino
File metadata and controls
89 lines (73 loc) · 2.64 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
// Light Stream.
// Waves of blue pulsing down 4 x 30m strands of NeoPixel lights.
// NeoPixel data wires plugged into Arduino pins 0-3, NeoPixel
// ground wires all connected to common ground. NeoPixel power
// lines plugged into 5V 20A brick power supply.
#include <Adafruit_NeoPixel.h>
#define N_LEDS 300 // 10 meter reel @ 30 LEDs/m
#define N_REELS 4 // Use pins 0 through N_REELS-1 to control each reel of NeoPixels
#define N_FISH 6 // Number of fish swimming upstream per reel
// The Arduino compiler won't let me do this in a loop
int pin = 0;
Adafruit_NeoPixel strip[] = {
Adafruit_NeoPixel(N_LEDS, pin++, NEO_GRB + NEO_KHZ800),
Adafruit_NeoPixel(N_LEDS, pin++, NEO_GRB + NEO_KHZ800),
Adafruit_NeoPixel(N_LEDS, pin++, NEO_GRB + NEO_KHZ800),
Adafruit_NeoPixel(N_LEDS, pin++, NEO_GRB + NEO_KHZ800)
};
uint16_t fish[N_FISH][N_REELS];
void setup() {
randomSeed(analogRead(0)); // Initialize random number generator using analog noise
int initial_fish_spacing = 50;
for (int p = 0; p < N_REELS; p++) {
for (int f = 0; f < N_FISH; f++) {
fish[f][p]= strip[p].numPixels() - 1 - (f * initial_fish_spacing);
}
strip[p].begin();
}
}
void loop() {
stream(0x3341FF); // Lighter blue
stream(0x334EFF);
stream(0x3351FF);
stream(0x336EFF); // Darker blue
}
static void stream(uint32_t c) {
uint16_t pixels_to_light = 15;
uint16_t bands = 12;
uint16_t band_length = floor(strip[0].numPixels()/bands);
for(uint16_t i=0; i<band_length; i++) {
for (int p = 0; p < N_REELS; p++) {
for (int f = 0; f < N_FISH; f++) {
strip[p].setPixelColor(fish[f][p], c); // Erase previous fish with water color
// Move the fish upstream 2/5 of the time
if (random(1, 6) < 3) {
fish[f][p]--;
}
if (fish[f][p] == 0) {
fish[f][p] = strip[p].numPixels()-1;
}
}
}
// Draw colored blue bands for waves
for(uint16_t b=0; b<bands; b++) {
for (int p = 0; p < N_REELS; p++) {
strip[p].setPixelColor(i+(b*band_length), c); // Draw new pixel
strip[p].setPixelColor(i+(b*band_length)-pixels_to_light, 0); // Erase pixel a few steps back
}
}
// Erase the last pixels on the strip from the previous run
if (i<=pixels_to_light) {
for (int p = 0; p < N_REELS; p++) {
strip[p].setPixelColor(strip[p].numPixels()-1-pixels_to_light+i, 0);
}
}
for (int p = 0; p < N_REELS; p++) {
for (int f = 0; f < N_FISH; f++) {
strip[p].setPixelColor(fish[f][p], 0xFF6666); // Fish swimming upstream
}
strip[p].show();
}
delay(35);
}
}