Hey Blynkers,
I need help with this project so the aim was the project was to
- Control RGB led strip with zeRGBa Widget and Alexa voice commands
- I want the colour change to be smooth and not sudden.
so I did write a code for the same and I am not a good coder at all so I need some help.
THE PROBLEM
the problem is that whenever I change the colour, The ESP8266 just crashes and boots up with the new colour
PLEASE NOTE THAT I AM USING BELKIN WEMO EMULATER ,WIFI MANAGER AND ARDUINO OTA.
not quite sure as to what went wrong
i know that i have modified the code quite a bit but when i use the same code to controll relays, it works fine.
i know these external library might be a problem so instead of saying the “external modifications are a problem” please take some time and explain me how in detail
PLEASE HELP ME OUT GUYS
okay so i fixed the problem by removing the while loop but i still want to change the light colours smoothly. so now the question is what loop should i use in order to chang the colour smoothly and without crashing the ESP
THE CODE
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <WiFiManager.h>
#include <ESP8266WebServer.h>
#include <BlynkSimpleEsp8266.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <SimpleTimer.h>
#include "WemoSwitch.h"
#include "WemoManager.h"
#include "CallbackFunction.h"
#define VPIN V1 //Use a unique virtual pin for each device using the same token / dashboard
char auth[] = "AUTH"; //Get token from Blynk
//Colour callbacks
WemoManager wemoManager;
WemoSwitch *light = NULL;
WemoSwitch *light1 = NULL;
WemoSwitch *light2 = NULL;
WemoSwitch *light3 = NULL;
WemoSwitch *light4 = NULL;
WemoSwitch *light5 = NULL;
WemoSwitch *light6 = NULL;
int BlynkR,BlynkG,BlynkB;
int redPin = 12;
int greenPin = 14;
int bluePin = 13;
int r = 0;
int g = 0;
int b = 0;
SimpleTimer timer;
void setup()
{
Serial.begin(115200);
WiFiManager wifi; //WiFiManager intialization.
wifi.autoConnect("RGB-LED STRIP"); //Create AP, if necessary
wemoManager.begin();
// Format: Alexa invocation name, local port no, on callback, off callback
light = new WemoSwitch("Bed Lights",1000, LightOn, LightOff);
light1 = new WemoSwitch("Blue Light",1001, BlueOn, BlueOff);
light2 = new WemoSwitch("Green Light",1002, GreenOn, GreenOff);
light3 = new WemoSwitch("Red Light",1003, RedOn, RedOff);
light4 = new WemoSwitch("Pink Light",1004, PinkOn, PinkOff);
light5 = new WemoSwitch("Purple Light",1005, PurpleOn, PurpleOff);
light6 = new WemoSwitch("Teal Light",1006, TealOn, TealOff);
wemoManager.addDevice(*light);
wemoManager.addDevice(*light1);
wemoManager.addDevice(*light2);
wemoManager.addDevice(*light3);
wemoManager.addDevice(*light4);
wemoManager.addDevice(*light5);
wemoManager.addDevice(*light6);
Blynk.config(auth);
ArduinoOTA.begin();
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
wemoManager.serverLoop();
Blynk.run();
ArduinoOTA.handle();
timer.run();
}
BLYNK_WRITE(VPIN) // zeRGBa assigned to V1
{
// get a RED channel value
BlynkR = param[0].asInt();
// get a GREEN channel value
BlynkG = param[1].asInt();
// get a BLUE channel value
BlynkB = param[2].asInt();
setColor(BlynkR, BlynkG, BlynkB);
}
void LightOn(){
setColor(1023, 1023, 1023);
}
void LightOff(){
setColor(0, 0, 0);
}
void BlueOn(){
setColor(0, 0, 1023);
}
void BlueOff(){
setColor(0, 0, 0);
}
void GreenOn(){
setColor(0, 1023, 0);
}
void GreenOff(){
setColor(0, 0, 0);
}
void RedOn(){
setColor(1023, 0, 0);
}
void RedOff(){
setColor(0, 0, 0);
}
void PinkOn(){
setColor(1023, 0, 800);
}
void PinkOff(){
setColor(0, 0, 0);
}
void PurpleOn(){
setColor(465, 0, 750);
}
void PurpleOff(){
setColor(0, 0, 0);
}
void TealOn(){
setColor(0, 718, 400);
}
void TealOff(){
setColor(0, 0, 0);
}
void setColor(int red, int green, int blue) {
while ( r != red || g != green || b != blue ) {
if ( r < red ) r += 5;
if ( r > red ) r -= 5;
if ( g < green ) g += 5;
if ( g > green ) g -= 5;
if ( b < blue ) b += 5;
if ( b > blue ) b -= 5;
_setColor();
}
}
void _setColor() {
analogWrite(redPin, r);
analogWrite(greenPin, g);
analogWrite(bluePin, b);