Advertisement
rosea4

Ch. 5 white book code

Mar 31st, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo myServo ;
  3. int const Servopin = 9 ;
  4. int const potentiometerPin = A0 ;
  5. int potentiometerVal ;
  6. int angle ;
  7. void setup()
  8. {
  9. myServo.attach(Servopin) ;
  10. Serial.begin(9600) ;
  11. }
  12. void loop()
  13. {
  14. potentiometerVal = analogRead(potentiometerPin) ;
  15. Serial.print("potentiometerVal: ") ;
  16. Serial.print(potentiometerVal);
  17. angle = map(potentiometerVal, 0, 1023, 0, 180) ;
  18. Serial.print(" angle: ");
  19. Serial.println(angle);
  20. myServo.write(angle) ;
  21. delay(500) ;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement