Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. char val; // Data received from the serial port
  2. long int inByte;
  3.  
  4. void setup()
  5. {
  6. //initialize serial communications at a 9600 baud rate
  7. Serial.begin(9600);
  8. establishContact(); // send a byte to establish contact until receiver responds
  9. }
  10.  
  11. void loop()
  12. {
  13. if (Serial.available() > 0) { // If data is available to read,
  14. // get incoming byte:
  15. inByte = Serial.read();
  16.  
  17. if (inByte == 'w') {
  18. //Do Stuff
  19. delay(100);
  20. }
  21. if(inByte == 'a'){
  22. //Do Stuff
  23. }
  24. else {
  25. Serial.println("Awaiting commands"); //send back a hello world
  26. delay(10);
  27. }
  28. }
  29. }
  30. void establishContact() {
  31. while (Serial.available() <= 0) {
  32. Serial.println("A"); // send a capital A
  33. delay(300);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement