Created
January 5, 2020 16:16
-
-
Save OneGneissGuy/52e9d41ed97531e8dc00125e3c6cdd48 to your computer and use it in GitHub Desktop.
arduino script to drive a neopixel christmas ornament
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_NeoPixel.h> | |
#define N_PIXELS 19 | |
#define LED_PIN 1 | |
int RandomBlinky = 0; | |
int Brightness = 120; // Brightness of the pixels is about 60% | |
int BlinkDelay = 15; | |
int i = 0; | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB +NEO_KHZ800); | |
void setup() | |
{ | |
strip.begin(); | |
strip.setBrightness(Brightness); // I ended up not using this. | |
for (i = 0; i < N_PIXELS; i++) // I think this should set the alternating | |
{ // Red Green pattern | |
if (i % 2 == 0) //Divide by 2. If the remainder is 0 the color is Red. | |
{ // Otherwise, the color is Green. | |
strip.setPixelColor( i, 10, 0, 0); // Red - Yes, it is very dim. | |
strip.show(); | |
} | |
else | |
{ | |
strip.setPixelColor( i, 0, 10, 0); // Green - It is also dim. | |
strip.show(); | |
} | |
} | |
} // end of setup() | |
void loop() | |
{ | |
RandomBlinky = random(16); // Choose a random NeoPixel. | |
// set the random pixel to white for sparkling | |
strip.setPixelColor( RandomBlinky, 35, 35, 35); // It is a dim White. | |
strip.show(); | |
delay(BlinkDelay); //Let the White show for a little bit. | |
//Set the random pixel back to the color it was, Red or Green | |
if (RandomBlinky % 2 == 0) | |
{ | |
strip.setPixelColor( RandomBlinky, 10, 0, 0); | |
strip.show(); | |
} | |
else | |
{ | |
strip.setPixelColor( RandomBlinky, 0, 10, 0); | |
strip.show(); | |
} | |
delay(200); //Don't do another White blinky for a little bit. | |
// Use a lower number to make the blinks happen faster. | |
} // End of loop() | |
/* | |
Instead of doing the brightness using the "strip.setBrightness(Brightness);", | |
how about setting Red to 150, 0, 0 and Green to 0, 150, 0? | |
And set the sparkle to 200,200,200. | |
This way the flash of the sparkle will be brighter than the brightness of the | |
rest of the colors on the ring. | |
Well, that was too bright. I used lower numbers for the colors in the sketch. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment