Created
February 18, 2013 15:51
-
-
Save benmanns/4978359 to your computer and use it in GitHub Desktop.
Control a servo with a potentiometer. Configured for a HITECH Deluxe HS-322HD.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
Servo servo; | |
const int analogPin = 0; | |
const int servoPin = 9; | |
// The minimum pulse width corresponding to 0-degrees on the servo. | |
// Default is 544. | |
const int servoMin = 600; | |
// The maximum pulse width corresponding to 180-degrees on the servo. | |
// Default is 2400. | |
const int servoMax = 2400; | |
// Connection layout: | |
// 5v out to | |
// potentiometer red | |
// servo red | |
// ground to | |
// potentiometer black | |
// servo black | |
// digital pin #{servoPin} to servo yellow | |
// potentiometer blue/out to analog pin #{analogPin} | |
void setup() | |
{ | |
servo.attach(servoPin, servoMin, servoMax); | |
} | |
void loop() | |
{ | |
int value = analogRead(analogPin); | |
// This maps potentiometer output in (0...1023) to servo input (0...179). | |
value = map(value, 0, 1023, 0, 179); | |
servo.write(value); | |
delay(15); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment