Advertisement
Guest User

goal is to be able to set servo to value entered in serial

a guest
Jul 28th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo myservo; // create servo object to control a servo
  4. // a maximum of eight servo objects can be created
  5.  
  6. int pos = 0; // variable to store the servo position
  7.  
  8. void setup()
  9. {
  10. myservo.attach(9); // attaches the servo on pin 9 to the servo object
  11. Serial.begin(9600);
  12. while (! Serial);
  13. Serial.println("Enter desired servo position");
  14. }
  15.  
  16. void loop()
  17. {
  18. String content = "";
  19. char character;
  20.  
  21. while (Serial.available())
  22. {
  23. character = Serial.read();
  24. delay(5);
  25. content.concat(character);
  26. }
  27. if (content != "")
  28. {
  29. int spos = atoi(content);
  30. myservo.write(spos);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement