From 5b3f64ae793267c1f75ff47fd2330994c7a30dac Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Sun, 11 Dec 2016 21:02:37 -0700 Subject: [PATCH] Make work with great variety of things --- README.md | 20 +++++++++------ holiday-lights.ino | 61 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 61 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 0e2af9b..1a9a731 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ I found a good 10A power supply for about $12 on Amazon. You can probably salvage one from some old thing. If you have under 80 lights, you can use an Adafruit Trinket. -I used an Adafruit Pro Trinket for mine, which has 150+ lights. +I used an Adafruit Pro Trinket for my 182-light display. (It's an issue of RAM). Of course, a standard Arduino will work just fine too! @@ -23,9 +23,9 @@ Of course, a standard Arduino will work just fine too! This was coded to color-correct a specific type of GRB LEDs on wires I got from Amazon. It's coded to match the lights we already have, which are biased toward yellow and amber. -You may have gotten lights wired RGB, in which case this is going to look very green. +You may have gotten lights wired GRB, in which case this is going to look very green. It should be just a matter of switching the first two bytes in each color definition -to go from GRB to RGB. +to go from RGB to GRB. @@ -33,7 +33,6 @@ Setup ------- Plug your lights into pin 6 (or whatever you set `PIN` to in the code). -Set `NUM_LEDS` in the code to how many are in your strip. Give the strip power and ground. If you have more than about 80 LEDs, you might need to provide an external @@ -42,7 +41,12 @@ You can plug the LED strip into the +5v on the power supply; You can power your microcontroller from the beefier power supply, too, so you don't have to run USB just to power the microcontroller. -The code as written wants pin 4 to be connected to ground. -When you disconnect it, -the whole strand goes white. -My family has a tradition of the tree going from colors to white on the morning of the 25th. + +Usage +------- + +Just provide power. + +If you connect `WHITE_PIN` to ground, +everything goes white, +which is a tradition in my family on xmas morning. diff --git a/holiday-lights.ino b/holiday-lights.ino index 866ced3..f1ab783 100644 --- a/holiday-lights.ino +++ b/holiday-lights.ino @@ -3,21 +3,42 @@ #include #endif -#define PIN 6 -#define NUM_LEDS 150 +// Which pin your LED strip is connected to +#ifdef Attiny85 +# define PIN 3 +#else +# define PIN 6 +#endif +// Which pin to pull to go full white. Comment to disable this feature. #define WHITE_PIN 4 -Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB | NEO_KHZ800); +// 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); const uint32_t colors[] = { - 0x440000, // Green - 0x44dd00, // Yellow - 0x44dd00, // Yellow - 0x22dd00, // Amber - 0x22dd00, // Amber - 0x00ff00, // Red - 0x008844, // Purple + 0x004400, // Green + 0xdd4400, // Yellow + 0xdd4400, // Yellow + 0xdd2200, // Amber + 0xdd2200, // Amber + 0x0000ff, // Red + 0x880044, // Purple 0x000088, // Blue }; @@ -26,13 +47,19 @@ const int ncolors = sizeof(colors) / sizeof(*colors); void setup() { strip.begin(); strip.show(); +#ifdef WHITE_PIN pinMode(WHITE_PIN, INPUT_PULLUP); +#endif + +#ifdef LED_PIN + pinMode(LED_PIN, OUTPUT); +#endif } void loop_color() { for (int i = 0; i < NUM_LEDS/12; i += 1) { int pos = random(NUM_LEDS); - if (random(100) < 20) { + if (random(100) < ACTIVITY) { int color = random(ncolors); strip.setPixelColor(pos, colors[color]); } else { @@ -57,9 +84,19 @@ void loop_white() { } void loop() { - if (digitalRead(WHITE_PIN)) { +#ifdef WHITE_PIN + if (! digitalRead(WHITE_PIN)) { loop_white(); } else { +#else + { +#endif loop_color(); } + +#ifdef LED_PIN + static bool led = true; + digitalWrite(LED_PIN, led); + led = !led; +#endif }