/**********************************************
*** An attempt to change my animations from ***
*** delay to millis, allowing a momentary ***
*** push button to interrupt sequence and ***
*** cycle through animation list. ***
**********************************************/
#include <FastLED.h> // included libraries make
#define VOLTS 5 // max power
#define PWR_LIMIT 500 // 500mA max current
#define LED_PIN 7 // data pin
#define NUM_LEDS 45 // total number of pixels
#define BRIGHTNESS 50 // set brightness level
CRGB leds [NUM_LEDS]; // initialize all pixels
uint8_t state = 0;
uint8_t i = 0;
unsigned long currentMillis;
unsigned long changeTime;
void setup()
{
FastLED.addLeds<WS2812B,LED_PIN,GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setMaxPowerInVoltsAndMilliamps( VOLTS, PWR_LIMIT);
delay(1000); // short delay for recovery
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
}
void loop()
{
currentMillis = millis();
if (currentMillis - changeTime > 20)
{
changeTime = currentMillis;
updateLEDs();
}
// Do other stuff here... like check buttons.
}
void updateLEDs()
{
switch (state)
{
case 0:
leds[i++] = CRGB::Yellow;
FastLED.show();
if (i == 15) {
state++; i = 0;
}
break;
case 1:
i++; if (i == 20) {
state++; i = 0;
}
break;
case 2:
leds[14 - i] = CRGB::Black;
i++;
FastLED.show();
if (i == 15) {
state++; i = 0;
}
break;
case 3:
i++; if (i == 20) {
state++; i = 0;
}
break;
case 4:
leds[i++] = CRGB::Blue;
FastLED.show();
if (i == 32) {
state++; i = 0;
}
break;
case 5:
i++; if (i == 20) {
state++; i = 0;
}
break;
case 6:
leds[31 - i] = CRGB::Black;
i++;
FastLED.show();
if (i == 32) {
state++; i = 0;
}
break;
case 7:
i++; if (i == 20) {
state++; i = 0;
}
break;
case 8:
leds[i++] = CRGB::Red;
FastLED.show();
if (i == 45) {
state++; i = 0;
}
break;
case 9:
i++; if (i == 20) {
state++; i = 0;
}
break;
case 10:
leds[44 - i] = CRGB::Black;
i++;
FastLED.show();
if (i == 45) {
state++; i = 0;
}
break;
case 11:
i++; if (i == 20) {
state = 0; i = 0;
}
default:
break;
}
}