/**********************************************
*** 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(2000); // short delay for recovery
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
}
void loop()
{
currentMillis = millis();
if (currentMillis - changeTime > 50)
{
changeTime = currentMillis;
updateLEDs();
}
// Do other stuff here... like check buttons.
}
void updateLEDs()
{
switch (state)
{
case 0:
leds[i++] = CRGB::Yellow;
FastLED.show();
if (i == 45)
{
state++;
i = 0;
}
break;
case 1:
i++;
if (i == 20)
{
state++;
i = 0;
}
break;
case 2:
leds[i++] = CRGB::Black;
FastLED.show();
if (i == 45)
{
state++;
i = 0;
}
break;
case 3:
i++;
if (i == 20)
{
state = 0;
i = 0;
}
default:
break;
}
}