Hello!
I am working on a DIY project revolving around an RGB strip, which I can control from my phone via Blynk. I am trying to have 2 “Modes” for the strip: one “Auto” mode where I will have more advanced color settings and animations, and a “Manual” mode where I can set a single color with the zeRGBa Widget in Blynk. I am currently accomplishing this with dedicated “Mode” buttons on Blynk and switch functions in my Arduino code. For the most part, everything is working as planned, but when I set the strip to “Auto” mode, it just strobes rapidly. This is my first real foray into Arduino AND Blynk, so I am sure I’m missing something, probably something very obvious. Any help would be greatly appreciated!
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_NeoPixel.h>
#define LED D2
#define LED_Count 300
Adafruit_NeoPixel strip = Adafruit_NeoPixel (LED_Count,LED,NEO_GRB + NEO_KHZ800);
BlynkTimer timer;
char auth[] = "My Authentication Token";
char ssid[] = "My WiFi";
char pass[] = "My Password";
int selectmode = 1;
int color;
int vPin1;
int vPin2;
int vPin3;
int Auto;
int Manual;
int Brightness = 50;
int R;
int G;
int B;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(LED,OUTPUT);
timer.setInterval(100L,Mode);
strip.begin();
strip.show();
strip.setBrightness(Brightness);
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V0);
Blynk.syncVirtual(V1);
Blynk.syncVirtual(V2);
Blynk.syncVirtual(V3);
Blynk.syncVirtual(V4);
Blynk.syncVirtual(V5);
Blynk.syncVirtual(V6);
}
BLYNK_WRITE(V0)
{
Brightness = param.asInt();
}
BLYNK_WRITE(V1)
{
vPin1 = param.asInt();
if (vPin1 == 1)
{
color = 1;
Blynk.virtualWrite(V2,LOW);
vPin2 = 0;
Blynk.virtualWrite(V3,LOW);
vPin3 = 0;
}
}
BLYNK_WRITE(V2)
{
vPin2 = param.asInt();
if (vPin2 == 1)
{
color = 2;
Blynk.virtualWrite(V1,LOW);
vPin1 = 0;
Blynk.virtualWrite(V3,LOW);
vPin3 = 0;
}
}
BLYNK_WRITE(V3)
{
vPin3 = param.asInt();
if (vPin3 == 1)
{
color = 3;
Blynk.virtualWrite(V1,LOW);
vPin1 = 0;
Blynk.virtualWrite(V2,LOW);
vPin2 = 0;
}
}
BLYNK_WRITE(V4)
{
if (Manual == 1)
{
R = param[0].asInt();
G = param[1].asInt();
B = param[2].asInt();
}
}
BLYNK_WRITE(V5)
{
Auto = param.asInt();
if (Auto == 1)
{
selectmode = 1;
Blynk.virtualWrite(V6,LOW);
Manual = 0;
}
}
BLYNK_WRITE(V6)
{
Manual = param.asInt();
if (Manual == 1)
{
selectmode = 2;
Blynk.virtualWrite(V5,LOW);
Auto = 0;
}
}
void Mode()
{
switch(selectmode)
{
if (Manual == 1)
{
vPin1 = 0;
vPin2 = 0;
vPin3 = 0;
}
case 1:
{
if ((vPin1 == 0) && (vPin2 == 0) && (vPin3 == 0))
{
color = 0;
}
switch(color)
{
case 0:
{
for (int i=0;i<LED_Count;i++)
{
strip.setPixelColor(i,0,0,0);
}
strip.show();
strip.setBrightness(Brightness);
break;
}
case 1:
{
for (int i=0;i<LED_Count;i++)
{
strip.setPixelColor(i,200,0,0);
}
strip.show();
strip.setBrightness(Brightness);
break;
}
case 2:
{
for (int i=0;i<LED_Count;i++)
{
strip.setPixelColor(i,0,0,200);
}
strip.show();
strip.setBrightness(Brightness);
break;
}
case 3:
{
for (int i=0;i<LED_Count;i++)
{
strip.setPixelColor(i,0,200,0);
}
strip.show();
strip.setBrightness(Brightness);
break;
}
}
}
case 2:
{
for (int i=0;i<LED_Count;i++)
{
strip.setPixelColor(i,R,G,B);
}
strip.show();
strip.setBrightness(Brightness);
break;
}
}
}
void loop()
{
Blynk.run();
timer.run();
}