I wrote a sketch that requires that one switch be hihg for it to function and then another switch must be high OR the arduino must seral.read 'T'. aand when that all is true then it writes a servo position and changes my led color and prints out x in the serial port.
The problem here is that nothing is working serial wise. the buttons all work, so when the loop is togggled i should see some output on the serial port but do not. I also can not make it toggle via sending it 'T'. help me please!
#include <Servo.h>
Servo myservo;
const int buttonPin = 2;
const int buttonDoor = 1;
const int ledRED = 13; // the pin that the LED is attached to
const int ledGREEN = 12; //green led
int servopos = 180;
void setup() {
Serial.begin(9600); // serial begin
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(digitalRead (buttonDoor) == HIGH || Serial.read() == 'T'){
if(digitalRead (buttonPin) == HIGH) {
if(servopos == 180) {
digitalWrite(ledGREEN, LOW);
digitalWrite(ledRED, HIGH);
Serial.println("door is locked");
myservo.write(90);
servopos = 90;
delay(300);
}
else {
digitalWrite(ledRED, LOW);
digitalWrite(ledGREEN, HIGH);
Serial.println("door is unlocked");
myservo.write(180);
servopos = 180;
delay(300);
}
}
}
}
The serial port uses pins 0 and 1, but you're already using them for something else. Stop using those pins and I suspect you'll find the serial port starts working properly again.
I'm with PeterH. You're using pin 1 for buttonDoor. You shouldn't be using that pin for anything but serial stuff, unless you have a board which doesn't have TX on pin 1 (eg Leonardo).
I can't see anything wrong with the logic (but it's almost 3AM over here so I could be wrong ;)). If the button works, so should reading T from the serial.
Are you sure you're sending it an uppercase 'T' and not a lowercase 't'?
If that's not it you might want to add some debug output to see if you're actually receiving that 'T'.