Servo Code – Bill Byrd
This question comes from Bill Byrd:
- LCDs, Servos, and Twitter4J
- Using Servos with Arduino
Question
//learning servos
//have not been able to get this to work
int myServo = 9;
//pin A0 has a pot attached, this pot will control servo
int Pin_potentiometer = A0;
//holds reading from pot
int Potentiometer_Value;
//We will be adjusting the voltage pulse to the servo
//this variable controls the length in time of the pulse
//int pulseWidth = 640;//640 left
//int pulseWidth = 1435;//1435 is center poz for my futaba servo
int pulseWidth = 2230;//2230 right
//in mike's final sketch, only the 2230 is un-commented
void setup() {
pinMode(myServo, OUTPUT);
pinMode(Pin_potentiometer, INPUT);
}
void loop() {
//sample the analog pin
Potentiometer_Value = analogRead(Pin_potentiometer);
//map raw value to the range we need to control servo with pot
pulseWidth = map(Pin_potentiometer, 0, 1023, 640, 2230);//per my futaba
digitalWrite(myServo, HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(myServo, LOW);
delayMicroseconds(20000 - pulseWidth);//dwell time
delay(80);
}
Your Challenge
Hint
Solution
My thoughts…
[fvplayer src=”https://vimeo.com/343056056″ transcript=”auto” splash=”https://i.vimeocdn.com/video/792102059_1280x720.jpg?r=pad” caption=”Servo Code – Bill Byrd”]
