Hi everyone,
I bought a continuous Rotation Servo and connected it with my Arduino. I made some code but the servo must stop when i push a button but that won't work... Can some one look at my code and help me out. Thanks and greetings Jeroen vdk
#include <Servo.h>
Servo myservo;
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 4;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
void setup() {
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
Serial.begin(9600);
}
void loop(){
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
//rotate left/right
if (buttonState1 == HIGH) {
myservo.write(0);
delay(400);
Serial.println("button1");
myservo.attach(10);
}
//rotate left/right
if (buttonState2 == HIGH) {
myservo.write(180);
delay(400);
Serial.println("button2");
myservo.attach(10);
}
//rotate stop
if (buttonState3 == HIGH) {
myservo.write(90);
delay(400);
Serial.println("button3");
myservo.detach();
}
}