- August 5th, 2016, 7:45 am#4875628Thanks to Tony Goacher for this reboot ring/strip code
Change the amount of pixels/leds in the code to match what you have
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUM_PIXELS 60
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
// NOTE
// NUMBER_COMETS x (COMET_LENGTH + COMET_SPACING) must be <= TOTAL_COMET_PIXELS
// The number of pixels in each comet
#define COMET_LENGTH 12
// The number of comets
#define NUMBER_COMETS 3
// The number of pixels between each comet
#define COMET_SPACING 8
// The total number of pixels in the strip dedicated to comets
#define TOTAL_COMET_PIXELS 60
// The direction of the comet 0 or 1
#define COMET_DIRECTION 0
// The max comet brightness
#define MAX_COMET_BRIGHTNESS 255
// The comet speed
#define SPEED 50
byte rgbyRedLevels[NUM_PIXELS];
void InitComet()
{
int iIndex=0;
byte byMasterPos=0;
byte byCometIndex=0;
memset(rgbyRedLevels,0,NUM_PIXELS);
for(byCometIndex = 0; byCometIndex < NUMBER_COMETS; byCometIndex++)
{
#if COMET_DIRECTION
byte byBrightness=0;
#else
byte byBrightness = MAX_COMET_BRIGHTNESS;
#endif
// Dim comet by length
byte byDim = MAX_COMET_BRIGHTNESS / COMET_LENGTH;
for( iIndex = 0 ; iIndex < COMET_LENGTH ; iIndex++)
{
rgbyRedLevels[byMasterPos++] = byBrightness;
#if COMET_DIRECTION
byBrightness += byDim;
#else
byBrightness -= byDim;
#endif
}
byMasterPos += COMET_SPACING;
}
}
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
Serial.begin(9600); // open the serial port at 9600 bps:
strip.begin();
strip.show(); // Initialize all pixels to 'off'
InitComet();
}
#if COMET_DIRECTION
void ProcessCometsDir()
{
byte iIndex=0;
byte byLast=0;
byte byDestPixel=0;
byte byOld=0;
byLast= rgbyRedLevels[TOTAL_COMET_PIXELS-1]; // Preserve the contents of the last pixel
for(iIndex =TOTAL_COMET_PIXELS-1 ; iIndex > 0 ; iIndex--)
{
rgbyRedLevels[iIndex] = rgbyRedLevels[iIndex-1];
}
rgbyRedLevels[0]= byLast; // Put what was the last pixel intio the first
for(iIndex =0 ; iIndex <TOTAL_COMET_PIXELS ; iIndex++)
{
strip.setPixelColor(iIndex,rgbyRedLevels[iIndex],0,0 );
}
strip.show();
delay(SPEED);
}
#else
void ProcessCometsDir()
{
byte iIndex=0;
byte byLast=0;
byte byDestPixel=0;
byte byOld=0;
byLast= rgbyRedLevels[0]; // Preserve the contents of the last pixel
for(iIndex =0 ; iIndex < TOTAL_COMET_PIXELS-1 ; iIndex++)
{
rgbyRedLevels[iIndex] = rgbyRedLevels[iIndex+1];
}
rgbyRedLevels[TOTAL_COMET_PIXELS-1]= byLast; // Put what was the last pixel intio the first
for(iIndex =0 ; iIndex <TOTAL_COMET_PIXELS ; iIndex++)
{
strip.setPixelColor(iIndex,rgbyRedLevels[iIndex],0,0 );
}
strip.show();
delay(SPEED);
}
#endif
void loop()
{
ProcessCometsDir();
}
Using Tapatalk