Two button on off one LED stop working with blynk

Dear Blynk,

I need help with my project :
Two Button with bounce and one LED. each button can toggle on off 1 LED.
My code is working without Blynk but when i write Blynk code, my sketch stop working.

Here is my sketch code :

#include <Bounce2.h>
//#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
//#include <SPI.h>
//#include <Ethernet.h>
//#include <BlynkSimpleEthernet.h>
#define BUTTON_PIN_1 2
#define BUTTON_PIN_2 3


#define LED_PIN 13

// Instantiate a Bounce object
Bounce debouncer1 = Bounce(); 

// Instantiate another Bounce object
Bounce debouncer2 = Bounce(); 

int ledState = LOW;           // the current state of the output pin
int lastButton2State = LOW;   // the previous reading from the first push button pin
int lastButton3State = LOW;   // the previous reading from the second push button pin
//char auth[] = "87f7dc3631a144fba33xxx";

void setup() {
  
  //Serial.begin(9600);
  //Blynk.begin(auth);
  // You can also specify server.
  // For more options, see BoardsAndShields/Arduino_Ethernet_Manual example
  //Blynk.begin(auth, "your_server.com", 8442);
  //Blynk.begin(auth, IPAddress(192,168,1,100), 8888);
  
  // Setup the first button with an internal pull-up :
  pinMode(BUTTON_PIN_1,INPUT_PULLUP);
  // After setting up the button, setup the Bounce instance :
  debouncer1.attach(BUTTON_PIN_1);
  debouncer1.interval(5); // interval in ms
  
   // Setup the second button with an internal pull-up :
  pinMode(BUTTON_PIN_2,INPUT_PULLUP);
  // After setting up the button, setup the Bounce instance :
  debouncer2.attach(BUTTON_PIN_2);
  debouncer2.interval(5); // interval in ms

  //Setup the LED :
  pinMode(LED_PIN,OUTPUT);

}

void loop() {
 // Blynk.run();
  buttonku();
}

void buttonku()
{
  // Update the Bounce instances :
  debouncer1.update();
  debouncer2.update();

  // Get the updated value :
  int value1 = debouncer1.read();
  int value2 = debouncer2.read();
  int reading1 = value1 == HIGH;
  int reading2 = value2 == HIGH;
  
  // Turn on the LED if either button is pressed :
  if (lastButton2State == LOW && reading1 == HIGH)
    {
    if (ledState == HIGH) {ledState = LOW;}
    else {ledState = HIGH;}
    digitalWrite(LED_PIN, ledState);}
    lastButton2State = reading1;
    if (lastButton3State == LOW && reading2 == HIGH)
    {
    if (ledState == HIGH) {ledState = LOW;}
    else {ledState = HIGH;}
    digitalWrite(LED_PIN, ledState);}
    lastButton3State = reading2;
}

SOLVED :smile:

Can not use pin 13, pin 2-8 OK.

Thanks

1 Like