Skip to content

Instantly share code, notes, and snippets.

@nervusvagus
Created Aug 11, 2021
Embed
What would you like to do?
# include <FastLED.h>
CRGBPalette16 sweep = CRGBPalette16(
CRGB::Blue,
CRGB::Green,
CRGB::Green,
CRGB::Green,
CRGB::Green,
CRGB::Green,
CRGB::Green,
CHSV( 90, 255, 255),
CHSV( 90, 255, 255),
CHSV( 90, 255, 255),
CRGB::Yellow,
CRGB::Yellow,
CRGB::Yellow,
CRGB::Yellow,
CRGB::Yellow,
CRGB::Yellow
);
const uint8_t SweepSize = 15;
# define NUM_LEDS 100
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<NEOPIXEL, 6>(leds, NUM_LEDS);
Serial.begin(112500);
}
const CRGB BackgroundColor = CRGB::Red;
void loop() {
for (int sweepPos = 0; sweepPos < NUM_LEDS; sweepPos++) {
fill_solid(leds, NUM_LEDS, BackgroundColor); // wasteful but easy
for (int i = 0; i < SweepSize; i++) {
int pos = i + sweepPos; // if(pos > NUM_LEDS){ sweepPos = 0;}
// if(pos < 0) continue; // not on the strip yet
// Serial.println(pos);
pos += NUM_LEDS;
leds[pos % NUM_LEDS] = ColorFromPalette(sweep, (255 / SweepSize) * i);
// set color// past the end of the strip
}
for (int i = 0; i < SweepSize; i++) {
int pos = i + sweepPos + 30; // if(pos > NUM_LEDS){ sweepPos = 0;}
// if(pos < 0) continue; // not on the strip yet
// Serial.println(pos);
pos += NUM_LEDS;
leds[pos % NUM_LEDS] = ColorFromPalette(sweep, (255 / SweepSize) * i);
// set color// past the end of the strip
}
FastLED.show();
FastLED.delay(50);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment