Hi
I have written a code which turns the servo motor 180 to the left then stops when button is pushed. And when button is pushed again it moves 180 to the right then stops. My question is how do i increase the speed of the servo motor
Here is my code retrospect to the question
#include <Servo.h>
// Set digital pin numbers:
const int servoPin = 8; // The number of the Servo pin
const int buttonPin = 9; // The number of the Pushbutton pin
int buttonState = 0; // Variable for reading the pushbutton status
int directionState = 0; // Variable for reading direction of the servo
Servo myservo; // Create servo object to control a servo
int pos = 0; // Variable to store the servo position
void setup() {
myservo.attach(8); // attaches the servo on pin 8 to the servo object
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
if (directionState == 0) {
//The button is pushed
if (buttonState == HIGH) {
directionState = 1;// The direction for the servo is clockwise
// goes from 0 degrees to 180 degrees in steps of 1 degree
for (pos = 0; pos < 180; pos = pos + 1)
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}
} else if (directionState == 1) {
// The button is pushed
if (buttonState == HIGH) {
directionState = 0; // The direction for the servo is anti-clockwise
// goes from 180 degrees to 0 degrees in steps of 1 degree
for (pos = 180; pos>=1; pos=pos-1)
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}
}
}
help will be much appreciated