I need help to write a code to spin a servo motor forward 10 degree for each press of push button and spin backward 10 degree for each press of another push button
hint : Servo motor is 360 degree
thanks
I need help to write a code to spin a servo motor forward 10 degree for each press of push button and spin backward 10 degree for each press of another push button
hint : Servo motor is 360 degree
thanks
Servo motor is 360 degree
As in continuous rotation? If so, throw it away. It can NOT be made to act like a real servo. Stop posting new threads trying to make it so.
PaulS:
Servo motor is 360 degree
As in continuous rotation? If so, throw it away. It can NOT be made to act like a real servo. Stop posting new threads trying to make it so.
It is a real servo .
Stop posting new threads trying to make it so.
???????
It is a real servo .
Is it, or is it not, a continuous rotation "servo"?
PaulS:
It is a real servo .
Is it, or is it not, a continuous rotation "servo"?
It is a real servo .
It is a real servo .
Why can't you just answer the question?
PaulS:
It is a real servo .
Why can't you just answer the question?
It is a real servo and it is not a continuous rotation .
OK. So what is the problem? That state change detection example shows how to determine when a switch becomes pressed (need to advance the servo) or released (do nothing).
The servo know (stupid name) or servo sweep example shows how to use the Servo library and position a servo.
It is not rocket science, then, to increment the position value when the switch becomes pressed and then tell the servo to move to the new position.
So, what pulse length do you use to send it to 0 degrees?
What pulse length do you use to send it to 359 degrees?
Divide that range by 36, and you've got a 10 degree increment.
thanks a lot for replies
Basic two button servo code. You can add +10 or -10 incrementing for each servo.
//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
Assign the pins nice names, then refer to them as "Hey, you!". No.