if ( Serial.read()=='0'){ //LED ON
digitalWrite(13,HIGH);
}
if ( Serial.read()=='1'){ //LED OFF
digitalWrite(13,LOW);
}
}
}
And as I use it by my pc serial monitor, it doesn't work, and when it works it returns me this symbol: ÿ
Apart of this, sometimes, it works but not in the correct way... it only works with the first "IF()" inside the IF(Serial.available()>0){,the rest of the code didnt work... so in this case, i just could open the pin 13 led.
// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later
//A very simple example of sending a string of characters
//from the serial monitor, capturing the individual
//characters into a String, then evaluating the contents
//of the String to possibly perform an action (on/off board LED).
int ledPin = 13;
String readString;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
Serial.println("serial on/off test 0021"); // so I can keep track
}
void loop() {
while (Serial.available()) {
delay(3);
char c = Serial.read();
readString += c;
}
if (readString.length() >0) {
Serial.println(readString);
if(readString.indexOf("on") >=0)
{
digitalWrite(ledPin, HIGH);
}
if(readString.indexOf("off") >=0)
{
digitalWrite(ledPin, LOW);
}
readString="";
}
}