 // and minimize distance between Arduino and first pixel.  Avoid connecting
 // on a live circuit...if you must, connect GND first.
 
-void setup() {
-  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
-  #if defined (__AVR_ATtiny85__)
-    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
-  #endif
-  // End of trinket special code
 
 
-  strip.begin();
-  strip.clear();
-  strip.show(); // Initialize all pixels to 'off'
-}
-
-void loop() {
-  strip.clear();
-//  strip.setBrightness(10);
-//  rainbow(20);
-  rainbowCycle(30);
-}
-
-// Slightly different, this makes the rainbow equally distributed throughout
-void rainbowCycle(uint8_t wait) {
-  uint16_t i, j, k;
-
-  uint8_t twinkles [2][4];
-  
-  twinkles[0][0] = random(0,NUM_PIXELS - 3);
-  twinkles[0][1] = twinkles[0][0] + 2;
-  twinkles[0][2] = 1;
-  twinkles[0][3] = 0;
-
-   twinkles[1][0] = random(0,NUM_PIXELS - 3);
-  twinkles[1][1] = twinkles[0][0] + 2;
-  twinkles[1][2] = 1;
-  twinkles[1][3] = 0;
-
-  for(j=0; j<256; j++) {
-    for(k=0; k<1; k++){
-      for(i=0; i< strip.numPixels(); i++) {
-        if(i < twinkles[k][0] || i > twinkles[k][1]){
-          strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
-        } else {
-        }
-      }
-
-      
-      for(i=twinkles[k][0]; i<= twinkles[k][1]; i++){
-          twinkles[k][3] = twinkles[k][3] + twinkles[k][2];
-  
-          if(twinkles[k][3] >= 255){
-            twinkles[k][3] = 255;
-            twinkles[k][2] = twinkles[k][2] * -1;
-          }
-  
-          if(twinkles[k][3] <= 0){
-            twinkles[k][3] = 0;
-            twinkles[k][2] = twinkles[k][2] * -1;
-          }
-          strip.setPixelColor(i, strip.Color(twinkles[k][3],twinkles[k][3], twinkles[k][3]));
-      }
-    }
-    strip.show();
-    delay(wait);
-  }
-}
+uint8_t twinkles [3][4];
+uint16_t first_color;
+int counter = 0;
 
 // Input a value 0 to 255 to get a color value.
 // The colours are a transition r - g - b - back to r.

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>

  WheelPos -= 170;
  return strip.Color((WheelPos * 3)/darkness, (255 - WheelPos * 3)/darkness, 0);
}

void updateTwinkle(){
  uint8_t i;
  for(i=twinkles[0][0];i<=(twinkles[0][0] + 2); i++){
    strip.setPixelColor(i, strip.Color(twinkles[0][2],twinkles[0][2],twinkles[0][2]));
  }
  twinkles[0][2] = twinkles[0][2] + twinkles[0][3];
  if(twinkles[0][2] >= 255){
    twinkles[0][2] = 255;
    twinkles[0][3] = twinkles[0][3] * -1;
  }
  
  if(twinkles[0][2] <= 0){
    twinkles[0][2] = 0;
    twinkles[0][3] = twinkles[0][3] * -1;
  }
}

void updateTwinkleLocation(){
  if( random(0,3) == 0){
    twinkles[0][0] = random(0, NUM_PIXELS-3);
  } 
}

void updateRainbow() {
  first_color = (first_color + 1) & 255;
 
  uint16_t i;
  // Update all the lights to be a rainbow starting at this color.
  for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + first_color) & 255));
  }
}

void show_strip() {
  strip.show();
}

TimedAction ta_updateTwinkle = TimedAction(15, updateTwinkle);
TimedAction ta_showStrip = TimedAction(1, show_strip);
TimedAction ta_updateRainbow = TimedAction(30, updateRainbow);
TimedAction ta_updateTwinkleLocation = TimedAction(1000, updateTwinkleLocation);


void setup() {

  strip.begin();
  strip.clear();
  strip.show(); // Initialize all pixels to 'off'

  randomSeed(analogRead(0));

  twinkles[0][0] = random(0,NUM_PIXELS - 3);
  twinkles[0][2] = 1;
  twinkles[0][3] = 10;
}


void loop() {
//  strip.setBrightness(10);

  // Setup standard rainbow
  ta_updateRainbow.check();
  ta_updateTwinkle.check();
  ta_updateTwinkleLocation.check();
  strip.show();
}
