Here we go, hope you get along with my “programm-chaos”
I have more modes with I works only if the MainButton is pressed. When a mode is running and an other mode get pressed, the old one switch of and the new pressed one goes on. Now I want, that the active mode, can not be seen only if you read it on LCD (works), it should be visible on the color from the relative button.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
char ssid[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
int LedPinD1 = D1;
int DimmValue = 0;
int BlinkValue = 0;
int OutputValue = 0;
byte SwitchMode1 = 0;
byte SwitchMode2 = 0;
byte SwitchMode3 = 0;
byte SwitchMode4 = 0;
byte MainButton = 0;
byte ClearLCD = 0;
byte varMainButton = 0;
byte varSwitchMode1 = 0;
byte varSwitchMode2 = 0;
byte varSwitchMode3 = 0;
byte varSwitchMode4 = 0;
BlynkTimer timer;
WidgetLCD lcd (V101); //LCD Widget attached to Pin V30
WidgetLED led (V100); //LED Widget attached to Pin V100
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode (LedPinD1, OUTPUT);
timer.setInterval(1000L, SerialMonitoring);
timer.setInterval(100L, Func_Modi);
lcd.clear();
varMainButton = 0;
varSwitchMode1 = 1;
varSwitchMode2 = 0;
varSwitchMode3 = 0;
varSwitchMode4 = 0;
}
void loop()
{
Blynk.run();
timer.run();
}
BLYNK_WRITE(V20) //MainButton
{
MainButton = param.asInt();
if (MainButton == 1) {
varMainButton = 1;
}
if (MainButton == 0) {
varMainButton = 0;
}
}
BLYNK_WRITE(V21) //Modus 1, LED ON/OFF
{
SwitchMode1 = param.asInt();
if (SwitchMode1 == 1) {
varSwitchMode1 = 1;
varSwitchMode2 = 0;
varSwitchMode3 = 0;
varSwitchMode4 = 0;
}
}
BLYNK_WRITE(V22) //Modus 2, LED SZENE
{
SwitchMode2 = param.asInt();
if (SwitchMode2 == 1) {
varSwitchMode1 = 0;
varSwitchMode2 = 1;
varSwitchMode3 = 0;
varSwitchMode4 = 0;
}
}
BLYNK_WRITE(V23) //Modus 3, LED DIMMER
{
SwitchMode3 = param.asInt();
if (SwitchMode3 == 1) {
varSwitchMode1 = 0;
varSwitchMode2 = 0;
varSwitchMode3 = 1;
varSwitchMode4 = 0;
}
}
BLYNK_WRITE(V24) //Modus 4, LED BLINKER
{
SwitchMode4 = param.asInt();
if (SwitchMode4 == 1) {
varSwitchMode4++;
varSwitchMode1 = 0;
varSwitchMode2 = 0;
varSwitchMode3 = 0;
}
}
BLYNK_WRITE(V50) //Clear LCD
{
ClearLCD = param.asInt();
if (ClearLCD == 1) {
lcd.clear();
}
}
BLYNK_WRITE(V25) //Slider DimmValue
{
DimmValue = param.asInt();
}
BLYNK_WRITE(V26) //Slider DimmValue
{
BlinkValue = param.asInt();
}
void SerialMonitoring() {
Serial.print ("varSwitchMode1 = ");
Serial.println (varSwitchMode1);
Serial.print ("varSwitchMode2 = ");
Serial.println (varSwitchMode2);
Serial.print ("varSwitchMode3 = ");
Serial.println (varSwitchMode3);
Serial.print ("varSwitchMode4 = ");
Serial.println (varSwitchMode4);
Serial.print ("varMainButton = ");
Serial.println (varMainButton);
Serial.print ("DimmValue = ");
Serial.println (DimmValue);
}
void Func_Modi() {
led.setValue(OutputValue);
Blynk.virtualWrite (V102, OutputValue);
analogWrite(LedPinD1, OutputValue);
if ((varSwitchMode1 == 1) && (varMainButton == 1)) {
lcd.print(0, 0, " MODE 1 ON ");
lcd.print(0, 1, " LED ON/OFF ");
OutputValue = 50;
Blynk.setProperty(V21, "color", "#23C48E"); // GREEN
Blynk.setProperty(V21, "label", "ON"); // ON
}
if ((varSwitchMode1 == 1) && (varMainButton == 0)) {
lcd.print(0, 0, " MODE 1 OFF");
lcd.print(0, 1, " LED ON/OFF ");
OutputValue = 0;
Blynk.setProperty(V21, "color", "#D3435C"); // RED
Blynk.setProperty(V21, "label", "OFF"); // OFF
}
if ((varSwitchMode2 == 1) && (varMainButton == 1)) {
lcd.print(0, 0, " MODE 2 ON ");
lcd.print(0, 1, " LED SZENE ");
OutputValue = 150;
Blynk.setProperty(V22, "color", "#23C48E"); // GREEN
Blynk.setProperty(V22, "label", "ON"); // ON
}
if ((varSwitchMode2 == 1) && (varMainButton == 0)) {
lcd.print(0, 0, " MODE 2 OFF");
lcd.print(0, 1, " LED SZENE ");
OutputValue = 0;
Blynk.setProperty(V22, "color", "#D3435C"); // RED
Blynk.setProperty(V22, "label", "OFF"); // OFF
}
if ((varSwitchMode3 == 1) && (varMainButton == 1)) {
lcd.print(0, 0, " MODE 3 ON ");
lcd.print(0, 1, " LED DIMMER ");
OutputValue = DimmValue;
Blynk.setProperty(V23, "color", "#23C48E"); // GREEN
Blynk.setProperty(V23, "label", "ON"); // ON
}
if ((varSwitchMode3 == 1) && (varMainButton == 0)) {
lcd.print(0, 0, " MODE 3 OFF");
lcd.print(0, 1, " LED DIMMER ");
OutputValue = 0;
Blynk.setProperty(V23, "color", "#D3435C"); // RED
Blynk.setProperty(V23, "label", "OFF"); // OFF
}
if ((varSwitchMode4 == 1) && (varMainButton == 1)) {
lcd.print(0, 0, " MODE 4 ON ");
lcd.print(0, 1, " LED BLINKER ");
OutputValue = 50;
Blynk.setProperty(V24, "color", "#23C48E"); // GREEN
Blynk.setProperty(V24, "label", "ON"); // ON
}
if ((varSwitchMode4 == 1) && (varMainButton == 0)) {
lcd.print(0, 0, " MODE 4 OFF");
lcd.print(0, 1, " LED BLINKER ");
OutputValue = 0;
Blynk.setProperty(V24, "color", "#D3435C"); // RED
Blynk.setProperty(V24, "label", "OFF"); // OFF
}
}