#include <FastLED.h>
#define NUM_LEDS 28
#define LED_PIN 3
CRGB leds [NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness (255);
}
void loop () {
Routine1();
Routine2();
}
//Sub-Routines below.
void Routine1() {
const uint32_t interval = 750UL; // half a 20BPM beat
static unsigned long lastOffsetTime = 0;
static uint32_t t0 = 0; // timebase
static uint16_t phase = 0; // which segment of sine
if(millis() - lastOffsetTime >= interval){
lastOffsetTime += interval;
t0 = millis() ; // update timebase
}
uint16_t sinBeat = beatsin16(20, 0, NUM_LEDS - 1, t0, phase);
leds [sinBeat] = CRGB::Blue;
fadeToBlackBy (leds, NUM_LEDS, 50);
FastLED.show();
}
void Routine2() {
const uint32_t interval1 = 1500UL; // half a 20BPM beat
static unsigned long lastOffsetTime1 = 0;
static uint32_t t01 = 0; // timebase
static uint16_t phase1 = 32768/2; // which segment of sine
if(millis() - lastOffsetTime1 >= interval1){
lastOffsetTime1 += interval1;
t01 = millis() ; // update timebase
}
uint16_t sinBeat1 = beatsin16(33.3, 0, NUM_LEDS - 1, t01, phase1);
leds [sinBeat1] = CRGB::Red;
fadeToBlackBy (leds, NUM_LEDS, 50);
FastLED.show();
}