Guest User

Untitled

a guest
Nov 25th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. int incomingByte;
  4.  
  5. Servo Xservo;
  6. Servo Yservo;
  7.  
  8. int xpos = 0;
  9. int ypos = 0;
  10.  
  11. void setup()
  12. {
  13. Serial.begin(9600);
  14. Xservo.attach(6);
  15. Yservo.attach(5);
  16. ypos = 90;
  17. xpos = 90;
  18. }
  19.  
  20.  
  21. void refresh(){
  22. Xservo.write(xpos);
  23. Yservo.write(ypos);
  24. }
  25.  
  26. void loop()
  27. {
  28. refresh();
  29.  
  30. if (Serial.available() > 0) {
  31. incomingByte = Serial.read();
  32.  
  33. if (incomingByte == 'U') {
  34. ypos = ypos - 10;
  35. refresh();
  36. }
  37. if (incomingByte == 'D') {
  38. ypos = ypos + 10;
  39. refresh();
  40. }
  41. if (incomingByte == 'L') {
  42. xpos = xpos + 10;
  43. refresh();
  44. }
  45. if (incomingByte == 'R') {
  46. xpos = xpos - 10;
  47. refresh();
  48. }
  49. if (incomingByte == 'C') {
  50. xpos = 90;
  51. ypos = 90;
  52. refresh();
  53. }
  54. }
  55. }
Add Comment
Please, Sign In to add comment