I wrote a sketch to toggle the servo position and my leds between 90 degrees and 180, and turn one led on and one off. But nothing is happening...Any help would be appreciated.
#include <Servo.h>
Servo myservo;
const int buttonPin = 2;
const int ledRED = 13; // the pin that the LED is attached to
const int ledGREEN = 12; //green led
int servopos = 180;
void setup() {
myservo.attach(5); // attach servo to pin 5
// initialize the LED pin as an output:
pinMode(ledRED, OUTPUT); // led as ouput
pinMode(ledGREEN, OUTPUT); //led as output
pinMode(buttonPin, INPUT); // nitialize pushbuttonpin as input
myservo.write(servopos);
}
void loop() {
if(buttonPin == HIGH) {
if(servopos == 180) {
digitalWrite(ledGREEN, LOW);
digitalWrite(ledRED, HIGH);
myservo.write(90);
servopos = 90;
delay(300);
}
else {
digitalWrite(ledRED, LOW);
digitalWrite(ledGREEN, HIGH);
myservo.write(180);
servopos = 180;
delay(300);
}
}
}