2016-11-27 10:26:04 -07:00
|
|
|
#include <Adafruit_NeoPixel.h>
|
|
|
|
#ifdef __AVR__
|
|
|
|
#include <avr/power.h>
|
|
|
|
#endif
|
|
|
|
|
2016-12-11 21:02:37 -07:00
|
|
|
// Which pin your LED strip is connected to
|
|
|
|
#ifdef Attiny85
|
|
|
|
# define PIN 3
|
|
|
|
#else
|
|
|
|
# define PIN 6
|
|
|
|
#endif
|
2016-11-27 10:26:04 -07:00
|
|
|
|
2016-12-11 21:02:37 -07:00
|
|
|
// Which pin to pull to go full white. Comment to disable this feature.
|
2016-11-27 18:06:09 -07:00
|
|
|
#define WHITE_PIN 4
|
|
|
|
|
2016-12-11 21:02:37 -07:00
|
|
|
// Order of the lights you got
|
|
|
|
|
|
|
|
// How many LEDs you have. It's okay if this is too big.
|
|
|
|
#ifdef Attiny85
|
|
|
|
# define NUM_LEDS 80
|
|
|
|
#else
|
|
|
|
# define NUM_LEDS 200
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// What percentage chance a chosen light has of being on
|
|
|
|
#define ACTIVITY 50
|
|
|
|
|
|
|
|
// Debug LED
|
|
|
|
#define LED_PIN 1
|
|
|
|
|
|
|
|
|
|
|
|
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_RGB | NEO_KHZ800);
|
2016-11-27 10:26:04 -07:00
|
|
|
|
|
|
|
const uint32_t colors[] = {
|
2016-12-11 21:02:37 -07:00
|
|
|
0x004400, // Green
|
|
|
|
0xdd4400, // Yellow
|
|
|
|
0xdd4400, // Yellow
|
|
|
|
0xdd2200, // Amber
|
|
|
|
0xdd2200, // Amber
|
|
|
|
0x0000ff, // Red
|
|
|
|
0x880044, // Purple
|
2016-11-27 10:26:04 -07:00
|
|
|
0x000088, // Blue
|
|
|
|
};
|
|
|
|
|
|
|
|
const int ncolors = sizeof(colors) / sizeof(*colors);
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
strip.begin();
|
|
|
|
strip.show();
|
2016-12-11 21:02:37 -07:00
|
|
|
#ifdef WHITE_PIN
|
2016-11-27 18:06:09 -07:00
|
|
|
pinMode(WHITE_PIN, INPUT_PULLUP);
|
2016-12-11 21:02:37 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LED_PIN
|
|
|
|
pinMode(LED_PIN, OUTPUT);
|
|
|
|
#endif
|
2016-11-27 10:26:04 -07:00
|
|
|
}
|
|
|
|
|
2016-11-27 18:06:09 -07:00
|
|
|
void loop_color() {
|
|
|
|
for (int i = 0; i < NUM_LEDS/12; i += 1) {
|
2016-11-27 10:26:04 -07:00
|
|
|
int pos = random(NUM_LEDS);
|
2016-12-11 21:02:37 -07:00
|
|
|
if (random(100) < ACTIVITY) {
|
2016-11-27 18:06:09 -07:00
|
|
|
int color = random(ncolors);
|
|
|
|
strip.setPixelColor(pos, colors[color]);
|
|
|
|
} else {
|
|
|
|
strip.setPixelColor(pos, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strip.show();
|
|
|
|
delay(240);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop_white() {
|
|
|
|
for (int i = 0; i < NUM_LEDS/12; i += 1) {
|
|
|
|
int pos = random(NUM_LEDS);
|
|
|
|
if (random(100) < 5) {
|
|
|
|
strip.setPixelColor(pos, 0x0);
|
2016-11-27 10:26:04 -07:00
|
|
|
} else {
|
2016-11-27 18:06:09 -07:00
|
|
|
strip.setPixelColor(pos, 0x99ffaa);
|
2016-11-27 10:26:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
strip.show();
|
2016-11-27 18:06:09 -07:00
|
|
|
delay(24);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2016-12-11 21:02:37 -07:00
|
|
|
#ifdef WHITE_PIN
|
|
|
|
if (! digitalRead(WHITE_PIN)) {
|
2016-11-27 18:06:09 -07:00
|
|
|
loop_white();
|
|
|
|
} else {
|
2016-12-11 21:02:37 -07:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
#endif
|
2016-11-27 18:06:09 -07:00
|
|
|
loop_color();
|
|
|
|
}
|
2016-12-11 21:02:37 -07:00
|
|
|
|
|
|
|
#ifdef LED_PIN
|
|
|
|
static bool led = true;
|
|
|
|
digitalWrite(LED_PIN, led);
|
|
|
|
led = !led;
|
|
|
|
#endif
|
2016-11-27 10:26:04 -07:00
|
|
|
}
|