Advertisement
Narayan

UnoFirmware

Oct 5th, 2022 (edited)
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. String message = "\"Temperature\": 25,\r\"Pressure\": 11,\r\"Light\": 1200";
  2. String command = "";
  3. char c;
  4. uint8_t i = 0;
  5.  
  6. void getData(){
  7.    Serial.print("{");
  8.    Serial.print(message);
  9.    Serial.print("}");
  10. }
  11.  
  12. bool checkInput(){
  13.    while(Serial.available()) {
  14.         char c = (char)
  15.         Serial.read();
  16.         if ( c == '\r' || c == '\n') {
  17.             return true;
  18.         }
  19.         command += c;
  20.     }
  21.     return false;
  22. }
  23. void setup(){
  24.    Serial.begin(115200);
  25. }
  26.  
  27. void loop(){
  28.    if(checkInput()) {
  29.       if ( String("getData") == command ){
  30.          Serial.print("Detected\r");
  31.          getData();
  32.       }else{
  33.          Serial.print("Not detected\r");
  34.       }
  35.       command = "";
  36.    }
  37.    delay(1000);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement