Advertisement
mikroavr

nextion_graph

Dec 12th, 2021
1,645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unsigned int data_pres = 0;
  2. unsigned int avg = 0;
  3.  
  4. #include <movingAvg.h>
  5. movingAvg avgPres(20);                                  
  6. #include <SoftwareSerial.h>
  7. SoftwareSerial nexSerial(3, 2); // RX, TX
  8.  
  9.  
  10. void setup() {
  11.   Serial.begin(9600);
  12.   nexSerial.begin(9600);                                          
  13.   pinMode(A0, INPUT);
  14.   avgPres.begin();
  15.   delay(1000);
  16. }
  17.  
  18. void loop() {
  19.   //data_pres = map(analogRead(A0),0,1024,0,255);  //Read the pot value ann map it to 0.255 (max value of waveform=255)
  20.   data_pres = analogRead(A0)*4;
  21.   avg = avgPres.reading(data_pres);
  22.   Serial.println(avg);
  23.   String Tosend = "add ";                                      
  24.     Tosend += 1;                                              
  25.     Tosend += ",";
  26.     Tosend += 0;                                              
  27.     Tosend += ",";
  28.     Tosend += data_pres;                                            
  29.     nexSerial.print(Tosend);
  30.     nexSerial.write(0xff);
  31.     nexSerial.write(0xff);
  32.     nexSerial.write(0xff);
  33.  
  34.   delay(5);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement