#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 2
Adafruit_NeoPixel strip = Adafruit_NeoPixel(50, PIN, NEO_GRB + NEO_KHZ800);
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.show(); // Initialize all pixels to 'off'
}
void loop() {
// Just color x LED of the strip with one color
//
//colorStrip( strip.Color( 0,255,0 ), 144 );
//delay( 2000 );
//colorStrip( strip.Color( 255,0,0 ), 20 );
//delay( 2000 );
// Show a color interpolation between GREEN and RED
// spread it over 144 LEDs
//
uint32_t green = strip.Color(0,255,0);
uint32_t red = strip.Color(255,0,0);
uint32_t color = 0;
for( int i=0; i< strip.numPixels(); i++ ){
color = colorInterpolate( red, green, 144, i );
strip.setPixelColor( i, color );
}
strip.show();
delay( 5000 );
}
// Fill x Dots of a given color and turn-off the others
void colorStrip( uint32_t color, uint16_t len ) {
for( uint16_t i=0; i<len; i++ ){
strip.setPixelColor( i, color );
}
for( uint16_t i=len; i<strip.numPixels(); i++ ){
strip.setPixelColor( i, 0 ); // black
}
strip.show();
}
// Interpolate a color between 2 other colors
uint32_t colorInterpolate( uint32_t fromColor, uint32_t toColor, uint16_t maxSteps, uint16_t position ){
// fromColor
uint8_t r = ( fromColor & ((uint32_t)0xFF << 16) ) >> 16;
uint8_t g = ( fromColor & ((uint32_t)0xFF << 8) ) >> 8;
uint8_t b = ( fromColor & ((uint32_t)0xFF) );
// toColor
uint8_t r2 = ( toColor & ((uint32_t)0xFF << 16) ) >> 16;
uint8_t g2 = ( toColor & ((uint32_t)0xFF << 8) ) >> 8;
uint8_t b2 = ( toColor & ((uint32_t)0xFF) );
// Interpolate
float ri = r - ( ((float)(r-r2)) /maxSteps * position);
float gi = g - ( ((float)(g-g2)) /maxSteps * position);
float bi = b - ( ((float)(b-b2)) /maxSteps * position);
return strip.Color( (int)ri, (int)gi, (int)bi );
}