indep color fading buttons and reverse fading
//declaration
int IR = 0;
int SR = 0;
int SG = 0;
int IG = 0;
int SPD = 300; //speed
int FadeTimerR;
int FadeTimerG;
String hexa;
void setup()
{
//your setup here
.
.
.
.
FadeTimerR = timer.setInterval(SPD, fadeR);
timer.disable(FadeTimerR); // disable it on boot
FadeTimerG = timer.setInterval(SPD, fadeG);
timer.disable(FadeTimerG); // disable it on boot
}
//styled buton
BLYNK_WRITE(V11) {
if (param.asInt() == 1) {
timer.deleteTimer(FadeTimerR);
FadeTimerR = timer.setInterval(SPD, fadeR);
} else {
IR = 0;
SR = 0;
timer.disable(FadeTimerR); // disable it on boot
}
}
//styled buton
BLYNK_WRITE(V13) {
if (param.asInt() == 1) {
timer.deleteTimer(FadeTimerG);
FadeTimerG = timer.setInterval(SPD, fadeG);
} else {
IG = 0;
SG = 0;
timer.disable(FadeTimerG); // disable it on boot
}
}
//fade function
void fadeR() {
if (IR <= 0) {
SR = 0;
}
if (IR >= 255) {
SR = 1;
}
if (SR == 0) {
IR = IR + 10; // fading
} else {
IR = IR - 10; //reverse fading
}
//test hexa
hexa = String(IR, HEX);
if (hexa.length() < 2) {
hexa = "0" + hexa; //add zero to get 00 HEX
}
color = "#" + hexa + "0000"; //RED FADING
Blynk.setProperty(V11, "onBackColor", color);
}
void fadeG() {
if (IG <= 0) {
SG = 0;
}
if (IG >= 255) {
SG = 1;
}
if (SG == 0) {
IG = IG + 10;
} else {
IG = IG - 10;
}
//test hexa
hexa = String(IG, HEX);
if (hexa.length() < 2) {
hexa = "0" + hexa; //add zero to get 00 HEX
}
color = "#00" + hexa + "00"; //GREEN FADING
Blynk.setProperty(V13, "onBackColor", color);
}
void loop() {
Blynk.run();
timer.run();
}