/* flash 3 Pixel LED strips randomly version 2
www. steamtraininfo.com.
This sketch uses 3
WS2812B pixel strips.
*/
#include <FastLED.h>
#define NUM_LEDS 15 /*the number of leds that will light. If */
//****************************
#define LED_PIN 6 // Connect to the data wires on the pixel strips
CRGB _leds[NUM_LEDS];
bool _isStartDone = false;
bool _isNumLedsEven = NUM_LEDS % 2 == 0;
uint8_t _halfLedSize = NUM_LEDS / 2;
uint8_t _startCycleCount = 0;
uint8_t _startPos = 0; // this is one position ahead
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(_leds, NUM_LEDS);
FastLED.setBrightness(100);
}
void loop() {
if (!_isStartDone) {
_animateStart();
} else {
fill_solid(_leds, NUM_LEDS, CRGB::Red);
FastLED.show();
}
}
void _animateStart() {
if (_isNumLedsEven)
_animateStartEven();
else
_animateStartOdd();
}
void _animateStartEven() {
_animateStart(_halfLedSize - _startPos - 1, _halfLedSize + _startPos);
}
void _animateStartOdd() {
_animateStart(_halfLedSize - _startPos - 1, _halfLedSize + _startPos - 1);
}
void _animateStart(uint8_t leftPos, uint8_t rightPos) {
EVERY_N_MILLISECONDS(60) {
// 2 waves outward
_leds[leftPos] = CRGB(255, 0, 0);
_leds[rightPos] = CRGB(255, 0, 0);
// Serial.print("leftPos:");
// Serial.print(leftPos);
// Serial.print(" rightPos:");
// Serial.print(rightPos);
// Serial.print(" _startPos:");
// Serial.print(_startPos);
// Serial.print(" _halfLedSize:");
// Serial.print(_halfLedSize);
// Serial.println();
_startPos++;
if (_startPos == _halfLedSize) {
_startCycleCount++;
_startPos = 0;
if (_startCycleCount == 2)
_isStartDone = true;
}
FastLED.show();
}
EVERY_N_MILLISECONDS(5) {
fadeToBlackBy(_leds, NUM_LEDS, 5);
FastLED.show();
}
}