I am trying to create a simple project using Blynk on D1 Mini where I can select any animation any time and that should play unless I stop that using my Blynk App. While everything else working perfectly, I am not able to figure out what is wrong on my theaterchaserainbow function, that while selected, my D1 gets disconnected and connected again. Here is the code.
I understood from various forum that I must use blynk.timer instead and set count more than 1000L in setup. But that won’t help me either for this particular theaterchaserainbow function. All other functions works perfectly. Any help would be greatly appreciated.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_NeoPixel.h>
#include <wifi_credentials.h>
#define BLYNK_PRINT Serial
#define myPixelPin D2
#define myPixels 16
char auth[] = "xxxxxxxmy_authxxxxxx";
int select;
BlynkTimer timer;
// Instatiate the NeoPixel from the ibrary
Adafruit_NeoPixel strip = Adafruit_NeoPixel(myPixels, myPixelPin, NEO_GRB + NEO_KHZ800);
// Timer to repeat animations
void myTimerEvent() {
if (select == 1) {
allOff();
} else if (select == 12) {
theaterChaseRainbow(50);
}
}
// NeoPixel all off Switch
BLYNK_WRITE(V0) {
int pinValue = param.asInt();
select = 1;
}
// Menu based Animation Selection
BLYNK_WRITE(V1) {
int pinValue = param.asInt();
switch (pinValue) {
case 1: // Item 1
select = 11;
break;
case 2: // Item 2
select = 12;
break;
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
strip.begin();
strip.show();
timer.setInterval(1000L, myTimerEvent);
}
void loop() {
Blynk.run();
timer.run(); // Initiates BlynkTimer;
}
// Theatre Chase Rainbow
//*****************************************************************************
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
// Clear Program
//*****************************************************************************
void allOff() {
for ( int i = 0; i < strip.numPixels(); i++ ) {
strip.setPixelColor(i, 0, 0, 0 );
}
strip.show();
}
// Default Wheel defination
//*****************************************************************************
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}