I am running Blynk on ESP8266 NodeMCU module with two Neopixels attached to it. It runs fine until it doesnt. It resets and the lamp goes back to its default state. Plus its annoying to watch to randomly turn on and off. I have tried adding caps but no joy. My code is as follows. Please let me know if anything stands out to you. Any help is greatly appreciated.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_NeoPixel.h>
char auth[] = "";
char ssid[] = "";
char pass[] = "";
Adafruit_NeoPixel strip1(45, D5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2(45, D6, NEO_GRB + NEO_KHZ800);
uint8_t bars[7] = {3, 9, 15, 21, 27, 34, 40};
uint8_t non_bars[38] = {1, 2, 4, 5, 6, 7, 8, 10, 11, 12, 13,
14, 16, 17, 18, 19, 20, 22, 23, 24,
25, 26, 28, 29, 30, 31, 32, 33, 35,
36, 37, 38, 39, 41, 42, 43, 44, 45};
bool power = true;
int lightMode = 3;
int brightness = 100;
long lastTime = 0;
long firstPixelHue = 0;
int delayTime = 10;
//--------------------------- Main program loops ---------------------------
void setup() {
strip1.begin();
strip1.show();
strip1.setBrightness(brightness);
strip2.begin();
strip2.show();
strip2.setBrightness(brightness);
Blynk.begin(auth, ssid, pass);
stateSync();
}
void loop() {
Blynk.run();
lightControl();
}
//--------------------------- Blynk Call Backs ---------------------------
BLYNK_WRITE(V0)
{
lightMode = param.asInt();
stateSync();
}
BLYNK_WRITE(V1)
{
brightness = param.asInt();
strip1.setBrightness(brightness);
strip2.setBrightness(brightness);
strip1.show();
strip2.show();
}
BLYNK_WRITE(V2)
{
power = param.asInt();
}
BLYNK_WRITE(V3)
{
delayTime = param.asInt();
}
BLYNK_WRITE(V4)
{
int R = param[0].asInt();
int G = param[1].asInt();
int B = param[2].asInt();
firstPixelHue = strip1.Color(R,G,B);
colorWipe(firstPixelHue);
}
//--------------------------- Light control functions ---------------------------
void lightControl(){
if((millis()-lastTime)>delayTime){
if(power){
switch(lightMode){
case 1:
colorWipe(firstPixelHue);
break;
case 2:
staticRainbow();
break;
case 3:
runningRainbow();
break;
}
}
else {
turnOff();
}
lastTime = millis();
}
}
void colorWipe(uint32_t color) {
for(int i=0; i<strip1.numPixels(); i++) {
strip1.setPixelColor(i, color);
strip2.setPixelColor(i, color);
}
strip1.show();
strip2.show();
}
void staticRainbow(){
for(int i=0; i<strip1.numPixels(); i++) {
strip1.setPixelColor(i, strip1.gamma32(strip1.ColorHSV(firstPixelHue)));
strip2.setPixelColor(i, strip2.gamma32(strip2.ColorHSV(firstPixelHue)));
}
strip1.show();
strip2.show();
firstPixelHue += 256;
}
void runningRainbow(){
for(int i=0; i<strip1.numPixels(); i++) {
int pixelHue = firstPixelHue + (i * 65536L / strip1.numPixels());
strip1.setPixelColor(i, strip1.gamma32(strip1.ColorHSV(pixelHue)));
strip2.setPixelColor(i, strip2.gamma32(strip2.ColorHSV(pixelHue)));
}
strip1.show();
strip2.show();
firstPixelHue += 256;
}
void turnOff(){
strip1.clear();
strip2.clear();
strip1.show();
strip2.show();
}
void stateSync(){
Blynk.virtualWrite(V0, lightMode);
Blynk.virtualWrite(V1, brightness);
Blynk.virtualWrite(V2, power);
Blynk.virtualWrite(V3, delayTime);
}