Hi!
i'm almost done with my little project
The only thing i need to figure out now, is that how i adjust the speed of a servo.
Help me with the following code: :
int ledPin = 13;
int inputPin1 = 2;
int inputPin2 = 4;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(inputPin1, INPUT);
pinMode(inputPin2, INPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop(){
if (digitalRead(inputPin1) == LOW) {
for(pos = 20; pos < 100; pos += 1) // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(30);
}else if (digitalRead(inputPin2) == LOW){
for(pos = 100; pos>=20; pos-=1) // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(30);
}
}