Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo myMotor;
- int potpin = 0; // analog pin used to connect the potentiometer
- int val; // variable to read the value from the analog pin
- void setup()
- {
- myMotor.attach(8);
- Serial.begin(9600);
- }
- void loop()
- {
- val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
- val = map(val, 0, 1023, 0, 169); // scale it to use it with the servo (value between 0 and 180)
- myMotor.write(val);
- Serial.println(val);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement