Advertisement
naivxnaivet

Hardware Serial Receive (ReadString + indexOf)

Nov 8th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. void setup()
  2. {
  3. Serial1.begin(9600);
  4. }
  5.  
  6. void loop()
  7. {
  8. checkCondition();
  9. }
  10.  
  11.  
  12. void checkCondition()
  13. {
  14. String s1 = Serial1.readString();// s1 is String type variable.
  15. //display same received Data back in serial monitor.
  16. if(s1.indexOf("a")>=0)
  17. {
  18. Serial1.println("a");
  19. }
  20. if(s1.indexOf("b")>=0){
  21.  
  22. Serial1.print("b");
  23. }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement