Code: Select all
int state,incoming1,incoming2;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(11,OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
state = Serial.read();
if (state == 49)
{
if (Serial.available() > 0) {
incoming1 = Serial.read();
if (Serial.available() > 0) {
incoming2 = Serial.read();
if ((incoming1==49) && (incoming2==51))
{
digitalWrite(13, HIGH);
}
else if ((incoming1==49) && (incoming2==49))
{
digitalWrite(11, HIGH);
}
}
}
}
else //(state ==48)
{
if (Serial.available() > 0) {
incoming1 = Serial.read();
if (Serial.available() > 0) {
incoming2 = Serial.read();
if ((incoming1==49) && (incoming2==51))
{
digitalWrite(13, HIGH);
}
else if ((incoming1==49) && (incoming2==49))
{
digitalWrite(11, HIGH);
}
}//get incoming2
}//get incoming1
}
}//end-getstate
Serial.print(state);
Serial.print(incoming1);
Serial.println(incoming2);
delay(200);
}
it first gets the state, '1' (49 in ascii) or '0' (48 in ascii) and then gets another 2 numbers which indicates the led number, if the state is 1 it turns on the led, else it turns off the led. for example, if i want to turn on led 13 ill type '113' and to turn off led 11 ill type '011'.
my problem is that it doesnt work when i try to turn them off. is anything wrong with the statement? or anything else? because they just dont turn off.
Thanks!
edit:
OMG! thats the most stupid mistake ive ever made!! instead of writing LOW to turn it off ive written HIGH. anyways, u can have a free copy of that code lol