Start a new topic

External Button Arduino-Nextion

#include <SoftwareSerial.h>

#include <Nextion.h>

SoftwareSerial nextion(2, 3);// Nextion TX to pin 2 and RX to pin 3 of Arduino

int boton = 5 ;

Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps

void setup() {

  Serial.begin(9600);

  myNextion.init();

pinMode (13, OUTPUT);

pinMode (12,OUTPUT);

pinMode (5, INPUT_PULLUP);

}

void loop() {

 

  String message = myNextion.listen(); //check for message

  if (message != "") { // if a message is received...

    Serial.println(message); //...print it out

  }

 

boton = digitalRead (5);

if (boton == LOW){

  Serial.println ("Aqui estoy");

  Serial.read ();

  while (message == "65 0 1 0 ffff ffff ffff") {

    Serial.println ("65 0 1 0 ggg ffff ffff");

    digitalWrite (13,HIGH);

  }

 while (message == "65 1 1 0 ffff ffff ffff") {

    digitalWrite (13,LOW);

    }

    while (message == "65 0 3 0 ffff ffff ffff") {

    digitalWrite (12,HIGH);

  }

  while (message == "65 2 3 0 ffff ffff ffff") {

    digitalWrite (12,LOW);

}

}

}


// THE PROBLEM IS THAT ONLY IF I  KEEP MY EXTERNAL BUTTON IN LOW 

AND THEM I PRESS THE NEXTION BUTTON IT TURN ON THE LED. BUT JUST IF I KEEP THE BUTTON PRESS. 


I WANT TO ACTIVATE THE LED WITH THE NEXTION STATE IF I PRESS THE BUTTON, NO IF A KEEP IT PRESSED.

Login or Signup to post a comment