in the code i have a servo move to 180 degrees if it detects that the button is in a HIGH state and it reads an H from the serial port. The individual pieces of the circuit work when being tested by them selves so its not hardware related as far as i can tell, I'm thinking it has something to do with the && operators? Any ideas?
#include <Servo.h>
Servo myservo;
const int buttonPin = 2;
const int ledPin = 13;
int incomingByte;
int buttonState = 0;
void setup(){
myservo.attach(9);
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (Serial.available() > 0) {
incomingByte = Serial.read();
}
if (incomingByte == 'H' && buttonState == HIGH) {
myservo.write(180);
delay(1500);
digitalWrite(ledPin, HIGH);
}
if (incomingByte == 'L' && buttonState == LOW) {
myservo.write(90);
delay(1500);
digitalWrite(ledPin, LOW);
}
}