Here is the slightly modified sketch… I changed the timing to every second and the increments from 10 to 100 to avoid sending too much data during diagnosis. Once it is working, you can remove the Serial.print() lines and adjust the timing and increments.
Otherwise I only had to correct a value from 1025 to 1023 in a couple of lines. ALSO I set it to print the brightness data output all the time, in the button void, not just when they are pressed (just to keep it to a single instance of print).
Now, I can NOT test this… it will not even compile on my setup, so hopefully there are no syntax errors.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = "xxx"; //WeMos D1 Mini
char ssid[] = "xxx";
char password[] = "xxx";
IPAddress server_ip (192, 168, 1, 154);
// Mac address should be different for each device in your LAN
IPAddress arduino_ip ( 192, 168, 1, 154);
IPAddress dns_ip ( 8, 8, 8, 8);
IPAddress gateway_ip ( 192, 168, 1, 1);
IPAddress subnet_mask(255, 255, 255, 0);
SimpleTimer timer;
#define UPButton D5 // Set increment button pin.
#define DNButton D6 // Set decrement button pin.
#define WLED D7 // Set LED (or mosfet) pin.
int brightness = 0; // Start on with LED OFF.
SimpleTimer timerBUTTONS; // Setup timerBUTTONS to check buttons.
/////////////////////////////////////////////////
void setup()
{
pinMode(UPButton, INPUT_PULLUP); // Set increment button pin to INPUT - Add _PULLUP if not already set in hardware.
pinMode(DNButton, INPUT_PULLUP); // Set decrement button pin to INPUT - Add _PULLUP if not already set in hardware.
Serial.begin(115200);
Serial.println();
WiFi.config(arduino_ip, gateway_ip, subnet_mask);
WiFi.begin(ssid, password);
Blynk.config(auth);
while (Blynk.connect(1000) == false) {
}
timerBUTTONS.setInterval(1000L, whiteLED); // Timer to run whiteLED function every second.
}
////////////////////////////////////////////////
BLYNK_WRITE(V0) // Slider Widget Function - runs every-time slider widget is physically moved.
{
brightness = param.asInt(); // Get slider value.
analogWrite(WLED, brightness); // Send slider value to LED or mosfet
Serial.print("Slider: ");
Serial.println(brightness);
}
/////////////////////////////////////////////////
void whiteLED() // This function checks buttons status and updates White LED and slider (frequency dependent on timer).
{
// Check increment button and respond.
if (digitalRead(UPButton) == LOW and brightness < 1023) { // Only do something if button pressed and brightness counter in range.
brightness += 100; // Increment counter by 100
Blynk.virtualWrite(V0, constrain(brightness, 0, 1023)); // Send feedback to Slider Widget - but keep within 0-1023
analogWrite(WLED, constrain(brightness, 0, 1023)); // Send data to LED - but keep within 0-1023
}
// Check decrement button and respond..
else if (digitalRead(DNButton) == LOW and brightness > 0) { // Only do something if button pressed and brightness counter in range.
brightness -= 100; // Decrement counter by 100
Blynk.virtualWrite(V0, constrain(brightness, 0, 1023)); // Send feedback to Slider Widget - but keep within 0-1023
analogWrite(WLED, constrain(brightness, 0, 1023)); // Send data to LED - but keep within 0-1023
}
else { // nothing happening here... move along :)
}
Serial.print("Button: ");
Serial.println(brightness);
}
/////////////////////////////////////////////////
/////////////////////////////////////////////////
void loop()
{
Blynk.run(); // Runs usual Blynk routine.
timerBUTTONS.run(); // Checks timer and runs whiteLED function.
}
