Evelynestallation Blog Post #4!

It’s been such a busy few weeks that I haven’t made it into the DKC! However, I do have more fun code! This one is a variation of the code I used in blog post #2, but this time it has sparkles added in. See if you can spot the difference! When I think about coding lights, adding sparkles is both one of my favorite things to do and one of the most difficult because it requires the inclusion of random selection. If I end up hard coding the lights, which I’m leaning towards, I’d definitely include this code!

Also, depending on the lights you get, this code may make your lights different colors. It’s set for RGB lights, which means that red is the first number in the “pixels.Color(x, 0, y)” command. However, some lights are GRB lights and would interpret the first number, or x, as the color green. If that’s the case, you can switch the x value and the 0!

If you want to choose your own colors, you can reference the chart on this website!

Rapid Tables RGB Color Chart

Happy coding!

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
#define PIN       5
#define NUMPIXELS 60

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 30

void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif

  pixels.begin(); 

}

void loop() {

 int x=255;
  int y = 0; 
  for (int z = 0; z<255; z++){
   
     for(int i=0; i<NUMPIXELS; i++) {
      
   pixels.setPixelColor(i, pixels.Color(x, 0, y));
   pixels.show(); 
   
   
   }
   long w= random(0,NUMPIXELS);
    pixels.setPixelColor(w, pixels.Color(255, 255, 255));
    pixels.show();
   delay(DELAYVAL);
   x--;
   y++; }

   for (int p = 0; p<255; p++){
   
     for(int i=0; i<NUMPIXELS; i++) {
      
   pixels.setPixelColor(i, pixels.Color(x, 0, y));
   pixels.show(); 
   
   
   }
   long w= random(0,NUMPIXELS);
    pixels.setPixelColor(w, pixels.Color(255, 255, 255));
    pixels.show();
   delay(DELAYVAL);
   x++;
   y--; }
   
 }