Hi,
This is my first post and I am just starting to learn arduino.
I'm trying to figure out how to set a servo positions by push three or four buttons. For example, button 1 = position A, button 3= position C, etc.
Can anyone help?
Thanks in advance!
Learn how to read a button: http://arduino.cc/en/tutorial/button
Learn how to position a servo: Servo - Arduino Reference
Connect those two together with some programming.
Servo/button test code.
//zoomkat servo button test 12-29-2011
// Powering a servo from the arduino usually *DOES NOT WORK*.
#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int button2 = 5; //button pin, connect to ground to move servo
int press2 = 0;
Servo servo1;
void setup()
{
pinMode(button1, INPUT);
pinMode(button2, INPUT);
servo1.attach(7);
digitalWrite(4, HIGH); //enable pullups to make pin high
digitalWrite(5, HIGH); //enable pullups to make pin high
}
void loop()
{
press1 = digitalRead(button1);
if (press1 == LOW)
{
servo1.write(170);
}
press2 = digitalRead(button2);
if (press2 == LOW)
{
servo1.write(10);
}
}
pinMode(button1, INPUT);
pinMode(button2, INPUT);
servo1.attach(7);
digitalWrite(4, HIGH); //enable pullups to make pin high
digitalWrite(5, HIGH); //enable pullups to make pin high
What happened to the names? Why did pins 4 and 5 go back to being numbers.
"'m not a number. I'm a name" - Bob Seger
Thank you all!!!