#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);
}
bool finished;
bool initOnce;
int counter;
unsigned long now;
const bool doBLEU = true;
const bool doRED = true;
const bool dwell;
void loop() {
now = millis();
if (doBLEU) {
counter = 300;
finished = false;
initOnce = true;
while (!finished)
Routine1();
// to remove last LED
FastLED.clear();
FastLED.show();
if (dwell) delay(2000);
}
if (doRED) {
counter = 750;
finished = false;
initOnce = true;
while (!finished)
Routine2();
// to remove last LED
FastLED.clear();
FastLED.show();
if (dwell) delay(2000);
}
}
// original being modified but not "corrected" or "improved"
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 (initOnce) {
lastOffsetTime = now;
t0 = now; // timebase
initOnce = false;
}
if(now - lastOffsetTime >= interval){
lastOffsetTime += interval;
t0 = now ; // update timebase
}
uint16_t sinBeat = beatsin16(20, 0, NUM_LEDS - 1, t0, phase);
fadeToBlackBy (leds, NUM_LEDS, 7);
leds [sinBeat] = CRGB::Blue;
FastLED.show();
if (!--counter) finished = true;
}
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
static uint16_t phase1 = 16384; // which segment of sine
if (initOnce) {
lastOffsetTime1 = now;
t01 = now; // timebase
initOnce = false;
}
if(now - lastOffsetTime1 >= interval1){
lastOffsetTime1 += interval1;
t01 = now ; // update timebase
}
uint16_t sinBeat1 = beatsin16(33.3, 0, NUM_LEDS - 1, t01, phase1);
fadeToBlackBy (leds, NUM_LEDS, 7);
leds [sinBeat1] = CRGB::Red;
FastLED.show();
if (!--counter) finished = true;
}
/* MY Sub-Routines below because I broke them fixing them fixin them
const uint32_t interval = 750UL; // half a 20BPM beat
const uint16_t phase = 0; // which segment of sine
void Routine1() {
static unsigned long lastOffsetTime = 0;
static uint32_t t0 = 0; // timebase
if (initOnce) {
lastOffsetTime = now;
t0 = now; // timebase
initOnce = false;
}
if(now - lastOffsetTime >= interval){
lastOffsetTime += interval;
t0 = now ; // update timebase
}
uint16_t sinBeat = beatsin16(20, 0, NUM_LEDS - 1, t0, phase);
fadeToBlackBy (leds, NUM_LEDS, 50);
leds [sinBeat] = CRGB::Blue;
FastLED.show();
if (!--counter) finished = true;
}
const uint32_t interval2 = 1500UL; // half a 20BPM beat
//const uint16_t phase1 = 32768/2; // which segment of sine
void Routine2() {
static unsigned long lastOffsetTime = 0;
static uint32_t t0 = 0; // timebase
if (initOnce) {
lastOffsetTime = now;
t0 = now; // timebase
initOnce = false;
}
if(now - lastOffsetTime >= interval2){
lastOffsetTime += interval2;
t0 = now ; // update timebase
}
uint16_t sinBeat = beatsin16(33.3, 0, NUM_LEDS - 1, t0, phase);
fadeToBlackBy (leds, NUM_LEDS, 50);
leds [sinBeat] = CRGB::Red;
FastLED.show();
if (!--counter) finished = true;
}
*/
ALTO777 VERSION