Hi,
I'm new to the Nextion and I'm looking for some help to fix a minor issue with my code.
I'm trying to take a contactless temperature reading of a user using the mlx90614 and if the temperature is above 38'C it will send an SMS. This works fine but I was trying to use a button on the screen that will allow the temperature check to happen.
At the minute, the button is ineffective and the readings are constant. I've used a "touch release event" for the button also. Any guidance would be appreciated.
Thanks,
Joe.
#include <Nextion.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
NexText tTempC = NexText(1, 5, "tTempC");
NexButton bScan = NexButton(1, 4, "bScan");
NexTouch *nex_listen_list[] =
{
&bScan,
NULL
};
float t = 0;
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
mlx.begin();
nexInit();
bScan.attachPop(bScanPopCallback, &bScan);
}
void loop(void)
{
nexLoop(nex_listen_list);
if(&bScan)
{
bScanPopCallback();
}
if (t > 38)
{
SMS();
Serial.print("tTemp.txt=");
Serial.print(""");
Serial.print("High Temperature");
//Serial.print(user_code_1);
Serial.print(""");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
else
{
Serial.print("tTemp.txt=");
Serial.print(""");
Serial.print("Temperature is ok");
Serial.print(""");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(3000);
}
}
void bScanPopCallback()
{
t = mlx.readObjectTempC();
static char temperatureCTemp[6];
dtostrf(t, 6, 2, temperatureCTemp);
tTempC.setText(temperatureCTemp);
}
void SMS()
{
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
delay(1000);
mySerial.println("ATCOPS?"); //Once the handshake test is successful
delay(1000);
mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
delay(1000);
mySerial.println("AT+CMGS="+############"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
delay(1000);
mySerial.print("Warning! High Temperature Recorded"); //text content
delay(1000);
mySerial.write(26);
}