#include <Servo.h>
Servo penguin; // create servo object to control a servo
// twelve servo objects can be created on most boards
Servo turn;
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int buttongreen = 8; // the number of the pushbutton pin
const int buttonred = 4; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int buttonStategreen = 0;
int buttonStatered = 0;
int pos = 0; // variable to store the servo position
int posg = 0;
int posr = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(buttongreen, INPUT);
pinMode(buttonred, INPUT);
penguin.attach(9); // attaches the servo on pin 9 to the servo object
turn.attach(7); // attaches the servo on pin 9 to the servo object
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
{
for (pos = 180; pos >= 90; pos -= 5) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
penguin.write(pos); // tell servo to go to position in variable 'pos'
delay(1); // waits 15ms for the servo to reach the position
}
for (pos = 90; pos <= 180; pos += 1) { // goes from 180 degrees to 0 degrees
penguin.write(pos); // tell servo to go to position in variable 'pos'
delay(100); // waits 15ms for the servo to reach the position
}
// read the state of the pushbutton value:
buttonStategreen = digitalRead(buttongreen);
}
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
;} else if (buttonStategreen == HIGH); {
// turn LED on:
digitalWrite(ledPin, HIGH);
{
for (posg = 180; posg >= 90; posg -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
turn.write(posg); // tell servo to go to position in variable 'pos'
delay(1); // waits 15ms for the servo to reach the position
}
for (posg = 90; posg <= 180; posg += 1) { // goes from 180 degrees to 0 degrees
turn.write(posg); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
} }
buttonStatered = digitalRead(buttonred);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
; else if (buttonStatered == HIGH); {
// turn LED on:
digitalWrite(ledPin, HIGH);
{
for (posr = 180; posr >= 90; posr -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
turn.write(posr); // tell servo to go to position in variable 'pos'
delay(1); // waits 15ms for the servo to reach the position
}
for (posg = 90; posr <= 180; posr += 1) { // goes from 180 degrees to 0 degrees
turn.write(posr); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
} }
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
I can't seem to figure out why I am getting the error message else with no previous if