Hello,
I got into some trouble with the Blink timer. I hooked up some Ws2812B to my Esp8266 and I want to control them with Blynk. I am using FastLED for my project as I am familiar with the functions.
So this is my Code:
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_AUTH_TOKEN ""
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "";
char pass[] = "";
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <FastLED.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
#define LED_PIN 14
#define NUM_LEDS 16
CRGB leds[NUM_LEDS];
uint8_t check0, check1;
void setup()
{
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
Serial.begin(115200);
FastLED.setBrightness(50);
Blynk.begin(auth, ssid, pass);
timer.setInterval(33, purpleBlink);
timer.setInterval(33, blueBlink);
}
CRGBPalette16 purplePalette = CRGBPalette16 (
CRGB::DarkViolet,
CRGB::DarkViolet,
CRGB::DarkViolet,
CRGB::DarkViolet,
CRGB::Magenta,
CRGB::Magenta,
CRGB::Linen,
CRGB::Linen,
CRGB::Magenta,
CRGB::Magenta,
CRGB::DarkViolet,
CRGB::DarkViolet,
CRGB::DarkViolet,
CRGB::DarkViolet,
CRGB::Linen,
CRGB::Linen
);
CRGBPalette16 bluePalette = CRGBPalette16 (
CRGB::Red,
CRGB::Green,
CRGB::Blue
);
void loop()
{
Blynk.run();
timer.run();
}
BLYNK_WRITE(V0){
check0 = param.asInt();
}
BLYNK_WRITE(V2){
check1 = param.asInt();
}
void purpleBlink(){
if(check0 == 1){
EVERY_N_MILLISECONDS(50){
leds[random8(0, NUM_LEDS - 1)] = ColorFromPalette(purplePalette, random8(), 255, LINEARBLEND);
fadeToBlackBy(leds, NUM_LEDS, 125);
}
FastLED.show();
}else{
FastLED.clear();
FastLED.show();
}
}
void blueBlink(){
if(check1 == 1){
EVERY_N_MILLISECONDS(50){
leds[random8(0, NUM_LEDS - 1)] = ColorFromPalette(bluePalette, random8(), 255, LINEARBLEND);
fadeToBlackBy(leds, NUM_LEDS, 125);
}
FastLED.show();
}else{
FastLED.clear();
FastLED.show();
}
}
First of all. When I call function purpleBlink it blinks like crazy as if my time Intervall is 1ms. The blueBlink is very similar but at another brightness level… I don’t know why but that doesn’t matter at the moment.
I tried something that confuses me even more. When I just call one timer like only timer.setInterval(33, purpleBlink);
it works like it supposed to do.
I’ve read that you can call multiple timers with just one timer. Is that right?
And is there an issue when I want to have the same frequency twice? (Like 33ms for purpleBlink and blueBlink)
I made 2 videos where you can see the LED strip
“1.gif” is how it is supposed to be “2.gif” is my error
Hope I expressed precisely enough.
Hope to hear from you guys. Thanks
J