BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Rele touch button httm

esp8266

#1

hello … i’m new … I have a simple code for triggering the relay and I … touch button HTTM
to activate the relay should somehow double click … and I need one click … can help any

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = “be5ac8c181904d37bfe5b8bf5e12ae2d”;
char ssid[] = “ASUS”;
char pass[] = “11111111”;

const int ledPin1 = 12;//d6
const int ledPin2 = 13;//d7
const int ledPin3 = 14;
const int ledPin4 = 15;
const int btnPin1 = 5;
const int btnPin2 = 4;
const int btnPin3 = 9;
const int btnPin4 = 1;

BlynkTimer timer;
void checkPhysicalButton();

int led1State = LOW;
int btn1State = HIGH;

int led2State = LOW;
int btn2State = HIGH;

int led3State = LOW;
int btn3State = HIGH;

int led4State = LOW;
int btn4State = HIGH;
.
BLYNK_CONNECTED() {

Blynk.syncVirtual(V12);
Blynk.syncVirtual(V13);
Blynk.syncVirtual(V14);
Blynk.syncVirtual(V15);

}

//------------------------------------
BLYNK_WRITE(V12) {
led1State = param.asInt();
digitalWrite(ledPin1, led1State);
}

BLYNK_WRITE(V13) {
led2State = param.asInt();
digitalWrite(ledPin2, led2State);
}
BLYNK_WRITE(V14) {
led3State = param.asInt();
digitalWrite(ledPin3, led3State);
}
BLYNK_WRITE(V15) {
led4State = param.asInt();
digitalWrite(ledPin4, led4State);
}
// -----------------------------

/// problem in this code
void checkPhysicalButton(){

if (digitalRead(btnPin1) == LOW) {

if (btn1State != LOW) {

  led1State = !led1State;
  digitalWrite(ledPin1, led1State);


  Blynk.virtualWrite(V12, led1State);
}
btn1State = LOW;

} else {
btn1State = HIGH;
}
// -----------------------------------------

if (digitalRead(btnPin2) == LOW) {
// btnState is used to avoid sequential toggles
if (btn2State != LOW) {

  // Toggle LED state
  led2State = !led2State;
  digitalWrite(ledPin2, led2State);

  // Update Button Widget
  Blynk.virtualWrite(V13, led2State);
}
btn2State = LOW;

} else {
btn2State = HIGH;
}

if (digitalRead(btnPin3) == LOW) {
// btnState is used to avoid sequential toggles
if (btn3State != LOW) {

  // Toggle LED state
  led3State = !led3State;
  digitalWrite(ledPin3, led3State);

  // Update Button Widget
  Blynk.virtualWrite(V14, led3State);
}
btn3State = LOW;

} else {
btn3State = HIGH;
}

if (digitalRead(btnPin4) == LOW) {
// btnState is used to avoid sequential toggles
if (btn4State != LOW) {

  // Toggle LED state
  led4State = !led4State;
  digitalWrite(ledPin4, led4State);

  // Update Button Widget
  Blynk.virtualWrite(V15, led4State);
}
btn4State = LOW;

} else {
btn4State = HIGH;
}
}

void setup()
{

Serial.begin(9600);

Blynk.begin(auth, ssid, pass);

pinMode(ledPin1, OUTPUT);
pinMode(btnPin1, INPUT_PULLUP);
digitalWrite(ledPin1, led1State);

pinMode(ledPin2, OUTPUT);
pinMode(btnPin2, INPUT_PULLUP);
digitalWrite(ledPin2, led2State);

pinMode(ledPin3, OUTPUT);
pinMode(btnPin3, INPUT_PULLUP);
digitalWrite(ledPin3, led3State);

pinMode(ledPin4, OUTPUT);
pinMode(btnPin4, INPUT_PULLUP);
digitalWrite(ledPin4, led4State);

timer.setInterval(500L, checkPhysicalButton);
}

void loop()
{
Blynk.run();
timer.run();
}