Hi everybody!
I am designing an HMI screen to control lights, with an optical sensor. The screen includes 2 buttons: 1 automatic button + 1 control button.
When pressing the automatic button, the optical sensor will work when it is morning, the light will turn off, when it is dark, the light will turn on.
When turning off the automatic mode, control the lights with the control button, on and off depending on the operator.
But the code I designed has problems. Hope anyone can help!!!!
#include "Nextion.h"
#define sensor_optical 7
#define DHT11modulePIN 4 // define the digital I/O pin
#define DHT11moduleTYPE DHT11 // DHT 11 module
#define LEDPIN 8 // define the digital I/O pin
// Declare Nextion objects
// The the following informations from Nextion Editor
// (page id, component id, component name)
NexDSButton bdslight = NexDSButton(0, 2, "bt0");
NexDSButton autocb = NexDSButton(0, 6, "bt1");
// Register objects to the touch event list
NexTouch *nex_listen_list[] = {
//&bdslight,
&autocb,
NULL
};
void bdslightPushCallback(void *ptr) {
uint32_t dual_state;
bdslight.getValue(&dual_state);
if(dual_state)
{
digitalWrite (LEDPIN, HIGH); // set the LED on
}
else
{
digitalWrite (LEDPIN, LOW); // set the LED off
}
}
void autocbPushCallback(void *ptr) {
uint32_t dual_state1;
autocb.getValue(&dual_state1);
if(dual_state1)
{
int tt =digitalRead(sensor_optical);
if(tt== 1)
{
digitalWrite(LEDPIN,HIGH);
}
else
{
digitalWrite(LEDPIN,LOW);
}
}
else
{
&bdslight;
}
}
void setup() {
Serial.begin(9600);
pinMode (LEDPIN, OUTPUT);
pinMode(sensor_optical, INPUT_PULLUP);
nexInit();
// Register the push/pop event callback function
bdslight.attachPush(bdslightPushCallback, &bdslight);
autocb.attachPush(autocbPushCallback, &autocb);
}
void loop() {
nexLoop(nex_listen_list);
}