Advertisement
Vendrick-Xander

Potentiometer Servo Code

Jan 15th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo servo;
  3. const int servoOut = 9;
  4. const int potIn = A0;
  5. void setup() {
  6. pinMode(servoOut, OUTPUT);
  7. pinMode(potIn, INPUT);
  8. servo.attach(9);
  9. Serial.begin(9600);
  10. }
  11.  
  12. void loop() {
  13. int data = analogRead(potIn);
  14. data = map(data, 0, 1023, 0, 180);
  15. Serial.println(data);
  16. servo.write(data);
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement