Behind today’s door is another 1-kohm resistor. But today you don’t have to change anything in the hardware layout from yesterday. Only a small detail changes on the interface.

Der Aufbau von gestern
The layout from yesterday

You don’t have to re-upload the programme because you’re simply manually adjusting the interface from yesterday. If you’d like to load the interface in the app anyway for safety’s sake, you’ll find the QR code here as usual. But then you also have to re-enter the token in your programme.

blynk_tag99

In order to make the changes manually, you first have to delete the button that was previously responsible for the LED at D9. To do this, tap briefly on the button while the interface is not started and tap the “delete” option below. There you’ll also be shown the energy that you “recycle.” Now, instead of the button, you have to insert a slider. To do this, tap on the plus sign at the top right and select “Slider_L.” The slider appears on the screen. By briefly tapping on the element, you reach its settings. Once you’re there, set “Output” to “Digital D9.” Note that after “D9” there’s a small red “PWM,” a little indication of how today’s test works. After these changes, you can start the interface by tapping the Play button at the top right.

What was previously possible only with the virtual LED is now also possible with real objects. You change the brightness of the LED at D9 by changing the slider position. Thus, for example, you can build a dimmable living room lamp that can be controlled via app. The keyword for this subject is PWM (pulse width modulation). Unlike with an incandescent light bulb, for example, you can’t simply dim an LED with less voltage. The procedure here is more complicated and functions by quickly switching the port on and off. The on and off times vary such that it looks like the LED becomes brighter or darker. The longer the on time is compared to the off time, the brighter the LED appears. The fact that the flickering of the LED can’t be seen or can barely be seen is due to the high speed with which the port is switched. With this procedure, you can also control engines or generate audio signals.

The sketch: A16_P09_Blynk5_PWM.ino
/*
Blynk 5: PWM
No Change to previous programm
Change ssid, password and token
*/

char ssid[] = "YourSSID";
char password[] = "YourPassword";
char token[] = "YourToken";

#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_SoftSer.h>
#include <BlynkSimpleShieldEsp8266_SoftSer.h>

// Set ESP8266 Serial object
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(11, 12); // RX, TX

#define BUTTON 7

ESP8266 wifi(EspSerial);

 WidgetLED led1(V0);
 WidgetLED led2(V1);

void setup()
{
  // Set console baud rate
  Serial.begin(19200);
  EspSerial.begin(19200);

  Blynk.begin(token, wifi, ssid, password);

  pinMode(BUTTON, INPUT_PULLUP);
}

void loop()
{
  Blynk.run();
  checkPin();
  checkPoti(); 
}

boolean currState = false ;

void checkPin()
{
  if (!digitalRead(BUTTON))
  {
    currState = !currState;

    //write current state to virtual LED
    if (currState){
       led1.on();
    }
    else{
       led1.off();
    }

    //wait till button is released
    while (!digitalRead(BUTTON)){  
    }
   
  }
}
int lastValue = 0;

void checkPoti()
{
  //read A0 and convert it to values 0-255
  int currValue = map(analogRead(A0), 0, 1023, 0, 255);

  //if values have changed write to virtual led2
  if (!(currValue == lastValue)){
      lastValue = currValue;
      Blynk.virtualWrite(V1, currValue);
  }
}

(The former Arduino Create embed is no longer available; the code is taken from the download of all sketches.)