Hi, I have a led strip controller with nodemcu which using blynk. In phone app I have button which toggle the fade, fade speed slider (500 - 10) and zeRGBa whose I use to control led when fade is turned off. When I set slider less than 100 my led start fading like no delay. How can I fix it?
Code:
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example runs directly on NodeMCU.
Note: This requires ESP8266 support package:
https://github.com/esp8266/Arduino
Please be sure to select the right NodeMCU module
in the Tools -> Board menu!
For advanced settings please follow ESP examples :
- ESP8266_Standalone_Manual_IP.ino
- ESP8266_Standalone_SmartConfig.ino
- ESP8266_Standalone_SSL.ino
Change WiFi ssid, pass, and Blynk auth token to run :)
Feel free to apply it to any other example. It's simple!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xx";
char pass[] = "xxxxxxxxx";
int REDPIN = 14;
int GREENPIN = 4;
int BLUEPIN = 5;
int toggle, FADESPEED, FADERECEIVE;
int r, g, b;
int ra, ga, ba;
BLYNK_WRITE(V1) //Button Widget is writing to pin V1
{
toggle = param.asInt();
}
BLYNK_WRITE(V0) // Widget zeRGBa WRITEs to Virtual Pin V0
{
ra = param[0].asInt(); // getting red value
ga = param[1].asInt(); // getting green value
ba = param[2].asInt(); // getting blue value
}
BLYNK_WRITE(V2) //Button Widget is writing to pin V1
{
FADERECEIVE = param.asInt();
Serial.println("Fade speed: ");
Serial.println(FADERECEIVE);
FADESPEED = FADERECEIVE * 0.01;
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
}
void loop()
{
if(toggle == 1){
r = 0;
g = 0;
b = 0;
for (r = 0; r < 1023; r++) {
analogWrite(REDPIN, r);
delay(FADESPEED);
if (toggle != 1){break;}
}
Serial.println("// fade from violet to red");
for (b = 1022; b > 0; b--) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
if (toggle != 1){break;}
}
Serial.println("// fade from red to yellow");
for (g = 0; g < 1023; g++) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
if (toggle != 1){break;}
}
Serial.println("// fade from yellow to green");
for (r = 1022; r > 0; r--) {
analogWrite(REDPIN, r);
delay(FADESPEED);
if (toggle != 1){break;}
}
Serial.println("// fade from green to teal");
for (b = 0; b < 1023; b++) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
if (toggle != 1){break;}
}
Serial.println("// fade from teal to blue");
for (g = 1022; g > 0; g--) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
if (toggle != 1){break;}
}
}else{
r = ra;
g = ga;
b = ba;
analogWrite(GREENPIN, g);
analogWrite(BLUEPIN, b);
analogWrite(REDPIN, r);
delay(10);
}
Blynk.run();
}