Trouble with mini servo motor
i new world of arduino , electronics. trying control mini servo 2 pushbuttons, 1 turn left , 1 right. want motor arm increment/decrement 10 degrees according button pressed. problem having arm swings way 0 or 180, rather going 10s. tried fix several times in code , i'm pretty sure wired correctly. code posted below. appreciated.
code: [select]
#include <servo.h> // servo library
servo servo1;
const int buttonlpin = 2;
const int buttonrpin = 3;
int buttonlstate;
int buttonrstate;
const int ledpin = 13;
void setup()
{
servo1.attach(9);
pinmode(buttonlpin, input);
pinmode(buttonrpin, input);
pinmode(13, output);
servo1.write(90);
}
void loop()
{
int position = servo1.read();
int buttonlstate;
int buttonrstate;
buttonlstate = digitalread(buttonlpin);
buttonrstate = digitalread(buttonrpin);
if((buttonlstate == low) && (buttonrstate == high))
{
servo1.write(position + 10);
}
if((buttonrstate == low) && (buttonlstate == high))
{
servo1.write(position - 10);
}
}
please edit post, , enclose code "code"-tag.
you should know how this - did read first sticky-post in every forum, didn't you?
http://forum.arduino.cc/index.php?topic=148850.0
// per.
you should know how this - did read first sticky-post in every forum, didn't you?
http://forum.arduino.cc/index.php?topic=148850.0
// per.
Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > Trouble with mini servo motor
arduino
Comments
Post a Comment