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.


Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > Trouble with mini servo motor


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support