Hello guys i am new in the world of arduino.
so i have look some examples and i start programming my ideas
(maybe my ideas are already in forum because they are simple)
so i try to connect 2 buttons in my arduino. that i want is, when i press the first button the servo will go from 0 ->180 and when i press the other button the servo will go from 180->0
i have write my code but only the first button works.
here is my code
IE always indent to reflect the nesting, always use { } for sub-statements that are more
than one line, using () instead of {} for a statement group isn't going to cut it except
by accident as here. Use whitespace liberally to make code readable - cramming
everything into one block without spaces is hard to read, hard to read = more bugs slip
by.
//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);
}
}