Advertisement
Guest User

Nextion_esempio_touch_text

a guest
Apr 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <Nextion.h>
  2. #include "NexButton.h"
  3. #include "NexText.h"
  4.  
  5. // button touch su pagina 0, con id 1 e nome 'b0'
  6. NexButton nx_btn = NexButton(0, 1, "b0");
  7.  
  8. // Text field su pagina 0 con id 3 e nome 't0'
  9. NexText nx_text = NexText(0, 3, "t0");
  10.  
  11. NexTouch *nexListenList[] =
  12. {
  13.   &nx_btn,
  14.   &nx_text,
  15.   NULL
  16. };
  17.  
  18. void buttonTouch() {
  19.     // codice da eseguire dopo evento touch sul nextion
  20. }
  21.  
  22. void setup(){
  23.     // init Nextion
  24.     nexInit();
  25.    
  26.     // registro evento touch sul button nx_btn
  27.     nx_btn.attachPop(buttonTouch, &nx_btn);
  28.    
  29. }
  30.  
  31. void loop(){
  32.  
  33.     // da chiamare ad ogni loop per mettersi in ascolto di eventi dal nextion
  34.     nexLoop(nexListenList);
  35.  
  36.     // Esempio di lettura da un DHT22 e scrittura valore su TextField nel Nextion
  37.     float dht_temp_new = dht.readTemperature();
  38.     if (dht_temp_new != dht_temp && dht_temp_new > 0) {
  39.         dht_temp = dht_temp_new;
  40.         char _dht_temp[10] = "";
  41.         itoa(dht_temp, _dht_temp, 10);
  42.  
  43.         // eseguo scrittura su TextField
  44.         nx_text.setText(_dht_temp);
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement