Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. unsigned long previousMillis = 0;
  2. const long interval = 250;
  3. int responseO;
  4. int responseR;
  5.  
  6. void setup() {
  7.  
  8. Serial.begin(9600);
  9. while (!Serial);
  10.  
  11. }
  12.  
  13. void loop() {
  14.  
  15. unsigned long currentMillis = millis();
  16.  
  17. if (currentMillis - previousMillis >= interval) //timer for every 250ms
  18. {
  19.  
  20. previousMillis = currentMillis;
  21.  
  22. Serial.println("R"); //Figured that "println" with a string for the character R should be ok
  23. if(Serial.available() >0) //Don't know if I am correct here, I was hoping that the serial would only be read if the device responded to the command R
  24. {responseR = Serial.read();} //Read serial for device's response to command R and save it in a variable
  25.  
  26.  
  27. Serial.println("O"); //Do the same thing for the command O
  28. if(Serial.available() >0)
  29. {responseO = Serial.read()}
  30.  
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement