Skip to content

Instantly share code, notes, and snippets.

@gelicia
Created April 21, 2018 20:39
Show Gist options
  • Save gelicia/c9bfd4b1bdee0f7cdc0d11351ba34524 to your computer and use it in GitHub Desktop.
Save gelicia/c9bfd4b1bdee0f7cdc0d11351ba34524 to your computer and use it in GitHub Desktop.
necklace rainbow code
#include <FastLED.h>
#define LED_PIN 11
#define NUM_LEDS 2
#define LED_TYPE WS2811
#define COLOR_ORDER RGB
CRGB leds[NUM_LEDS];
#define UPDATES_PER_SECOND 100
uint8_t startIndex = 0;
void setup() {
Serial.begin(9600);
delay( 3000 ); // power-up safety delay
FastLED.setMaxPowerInVoltsAndMilliamps(5, 500);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
void loop() {
static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */
FillLEDsFromPaletteColors(startIndex);
FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
}
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
for ( int i = 0; i < NUM_LEDS; i++) {
uint8_t colorIdx = map(i, 0, NUM_LEDS, 0, 255) + colorIndex;
leds[i] = ColorFromPalette( RainbowColors_p, colorIdx, 255, LINEARBLEND);
colorIndex += 3;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment