Trying to implement this code but I'm missing an error. I guess it has to be with my conditions, but I have not figured it out the solution.
#include <Servo.h>
Servo servoLeft;
Servo servoRight;
#define downbutton 7
#define upbutton 9
void setup()
{
servoLeft.attach(3);
servoRight.attach(5);
pinMode(downbutton, INPUT);
pinMode(upbutton, INPUT);
}
void loop() {
int buttonstate1 = digitalRead(downbutton); // Two States for buttons
int buttonstate2 = digitalRead(upbutton);
int pos = 20;
int neg = 70;
int pos2 = 20;
int neg2 = 70;
for(pos < 70; pos += 5; neg > 20; neg += -5){ // goes from 0 degrees to 110 degrees and viceversa in steps of 5 degree
if(buttonstate1 == true){ //button is high
servoLeft.write(pos); // tell servo to go to position in variable 'pos'
servoRight.write(neg); // tell servo to go to position in variable 'neg'
delay(1000); // wait 1 second
}
}
for(pos2 < 70; pos2 += 5; neg2 > 20; neg2 += -5){ // goes from 0 degrees to 110 degrees and viceversa in steps of 5 degree
if(buttonstate2 == true){ //button is high
servoLeft.write(neg); // tell servo to go to position in variable 'neg'
servoRight.write(pos); // tell servo to go to position in variable 'pos'
delay(1000); // wait 1 second
}
}
}