Good Day,
I am working on a side project to control 4 relays through my Nextion with an Arduino Nano. I get text and the rest to work but just no response from buttons. Can someone please shed some light if am doing something wrong?
#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 "EasyNextionLibrary.h" // Include EasyNextionLibrary
#include "Nextion.h"
char buffer[100] = {0};
uint32_t dual_state=0;
uint32_t number5 = 0; // Create variable to store value we are going to get
NexText t0 = NexText(0,2, "t0");
NexText t1 = NexText(0,3, "t1");
NexText t2 = NexText(0,4, "t2");
NexText t3 = NexText(0,5, "t3");
NexText t4 = NexText(0,6, "t4");
NexText t5 = NexText(0,7, "t5");
NexDSButton bt0 = NexDSButton(0,8, "bt0");
NexDSButton bt1 = NexDSButton(0,9, "bt1");
NexDSButton bt2 = NexDSButton(0,10, "bt2");
NexDSButton bt3 = NexDSButton(0,11, "bt3");
String text1,text2 ;
NexTouch *nex_listen_list[] = {
&bt0,
&bt1,
&bt2,
&bt3,
NULL
};
uint32_t next;
void the_temperture() {
t0.setText("36");
}
void the_humidity() {
t1.setText("40");
}
void the_pressure() {
t2.setText("666");
}
void the_iaq() {
t3.setText("402");
}
void the_co2() {
t4.setText("565");
}
void the_voc() {
t5.setText("340");
}
void bt0PopCallback(void *ptr) // Release event for dual state button bt0
{
number5 = 0; // Create variable to store value we are going to get
bt0.getValue(&number5); // Read value of dual state button to know the state (0 or 1)
if(number5 == 1){ // If dual state button is equal to 1 (meaning is ON)...
digitalWrite(5, HIGH); // Turn ON internal LED
}else{ // Since the dual state button is OFF...
digitalWrite(5, LOW); // Turn OFF internal LED
}
} // End of release event
void bt1PopCallback(void *ptr) // Release event for dual state button bt0
{
number5 = 0; // Create variable to store value we are going to get
bt1.getValue(&number5); // Read value of dual state button to know the state (0 or 1)
if(number5 == 1){ // If dual state button is equal to 1 (meaning is ON)...
digitalWrite(4, HIGH); // Turn ON internal LED
}else{ // Since the dual state button is OFF...
digitalWrite(4, LOW); // Turn OFF internal LED
}
} // End of release event
void bt2PopCallback(void *ptr) // Release event for dual state button bt0
{
number5 = 0; // Create variable to store value we are going to get
bt2.getValue(&number5); // Read value of dual state button to know the state (0 or 1)
if(number5 == 1){ // If dual state button is equal to 1 (meaning is ON)...
digitalWrite(6, HIGH); // Turn ON internal LED
}else{ // Since the dual state button is OFF...
digitalWrite(6, LOW); // Turn OFF internal LED
}
} // End of release event
void bt3PopCallback(void *ptr) // Release event for dual state button bt0
{
number5 = 0; // Create variable to store value we are going to get
bt3.getValue(&number5); // Read value of dual state button to know the state (0 or 1)
if(number5 == 1){ // If dual state button is equal to 1 (meaning is ON)...
digitalWrite(7, HIGH); // Turn ON internal LED
}else{ // Since the dual state button is OFF...
digitalWrite(7, LOW); // Turn OFF internal LED
}
} // End of release event
void setup()
{
nexSerial.begin(9600);
Serial.begin(9600); // Begin the object with a baud rate of 9600
// If no parameter was given in the begin(), the default baud rate of 9600 will be used
nexInit();
/* Register the pop event callback function of the dual state button component. */
bt0.attachPop(bt0PopCallback, &bt0);
bt1.attachPop(bt1PopCallback, &bt1);
bt2.attachPop(bt2PopCallback, &bt2);
bt3.attachPop(bt3PopCallback, &bt3);
//setting port OUTPUT
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
//initializing port
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
dbSerialPrintln("setup done");
the_voc();
the_co2();
the_iaq();
the_pressure();
the_humidity();
the_temperture();
}
void loop()
{
nexLoop(nex_listen_list);
}