Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Nextion.h>
- #include "NexButton.h"
- #include "NexText.h"
- // button touch su pagina 0, con id 1 e nome 'b0'
- NexButton nx_btn = NexButton(0, 1, "b0");
- // Text field su pagina 0 con id 3 e nome 't0'
- NexText nx_text = NexText(0, 3, "t0");
- NexTouch *nexListenList[] =
- {
- &nx_btn,
- &nx_text,
- NULL
- };
- void buttonTouch() {
- // codice da eseguire dopo evento touch sul nextion
- }
- void setup(){
- // init Nextion
- nexInit();
- // registro evento touch sul button nx_btn
- nx_btn.attachPop(buttonTouch, &nx_btn);
- }
- void loop(){
- // da chiamare ad ogni loop per mettersi in ascolto di eventi dal nextion
- nexLoop(nexListenList);
- // Esempio di lettura da un DHT22 e scrittura valore su TextField nel Nextion
- float dht_temp_new = dht.readTemperature();
- if (dht_temp_new != dht_temp && dht_temp_new > 0) {
- dht_temp = dht_temp_new;
- char _dht_temp[10] = "";
- itoa(dht_temp, _dht_temp, 10);
- // eseguo scrittura su TextField
- nx_text.setText(_dht_temp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement