I would like some help here. For some reason the buttons on Nextion are not working. Does anyone knows what's the problem?
It is suppose to change a NexText
(a text box in Nextion) while I press the button bOn
but it does nothing. Only the button of emergency (bEmergencia
) is working, it just changes the page0
to page 1.
#include <SoftwareSerial.h>
//bibliotecas nextion
#include <doxygen.h>
#include <NexButton.h>
#include <NexCheckbox.h>
#include <NexConfig.h>
#include <NexCrop.h>
#include <NexDualStateButton.h>
#include <NexGauge.h>
#include <NexGpio.h>
#include <NexHardware.h>
#include <NexHotspot.h>
#include <NexNumber.h>
#include <NexObject.h>
#include <NexPage.h>
#include <NexPicture.h>
#include <NexProgressBar.h>
#include <NexRadio.h>
#include <NexRtc.h>
#include <NexScrolltext.h>
#include <NexSlider.h>
#include <NexText.h>
#include <NexTimer.h>
#include <Nextion.h>
#include <NexTouch.h>
#include <NexUpload.h>
#include <NexVariable.h>
#include <NexWaveform.h>
#include "Nextion.h"
SoftwareSerial mySerial(0,1);
int contacto1 = 0;
int contacto2 = 0;
int contacto3 = 0;
int n0 = 0;
int n1 = 0;
int n2 = 0;
//pagina inicial block
NexButton bOn = NexButton(0, 9, "b0");
NexButton bOff = NexButton(0, 7, "b1");
NexButton bEmergencia = NexButton(0, 8, "b2");
NexText pecas_tapete1 = NexText(0, 10, "t0");
NexText pecas_tapete2 = NexText(0, 11, "t3");
NexText pecas_tapete3 = NexText(0, 12, "t4");
NexText estado_sistema = NexText(0, 2, "t1");
NexTouch *nex_listen_list[] =
{
//Eventos que são aguardados via interface serial
&bOn,
&bOff,
&bEmergencia,
NULL
};
void sistema_ligado(){
estado_sistema.setText("Sistema Ligado!");
}
void sistema_desligado(){
estado_sistema.setText("Sistema Desligado!");
}
void sistema_emergencia(){
//mudar p pagina 1
}
void setup()
{
//Inicializa a comunicacao com o display
nexInit();
//Define os pinos dos reles como entrada
pinMode (8, INPUT);
pinMode (9, INPUT);
pinMode (10, INPUT);
//Inicia a serial
Serial.begin(9600);
//Define a rotina que sera executada quando o Arduino
//receber dados do display
bOn.attachPush(sistema_ligado);
bOff.attachPush(sistema_desligado);
bEmergencia.attachPush(sistema_emergencia);
}
void loop()
{
delay(1000);
nexLoop(nex_listen_list);
if (sistema_ligado == true){
contacto1 = digitalRead(8);
contacto2 = digitalRead(9);
contacto3 = digitalRead(10);
Serial.write("n0.val=");
Serial.println(n0);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.write("n1.val=");
Serial.println(n1);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.write("n2.val=");
Serial.println(n2);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
if (contacto1 == HIGH && contacto2 == LOW && contacto3 == LOW){
n0++;
//delay(1000);
}
if (contacto2 == HIGH && contacto3 == LOW && contacto1 == LOW){
n1++;
//delay(1000);
}
if (contacto3 == HIGH && contacto1 == LOW && contacto2 == LOW){
n2++;
//delay(1000);
}
}
}