Hey guys,
Hoping someone could help with this small bit of code. I mad a small sketch to light a LED connected the pin which the user selects over the serial connection, eg type 13 to turn on the LED on pin 13, 07 to turn on LED on pin 7 etc...
I heavily used the code from Gian Pablo Villamil (username gpvillamil) posted here:
http:// http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1160543432Here's my code
byte incomingByte ;
int LEDpin;
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available()) { // if serial data waiting
digitalWrite(LEDpin,LOW); // if so, turn off previously lit LED
LEDpin = 0; // reset pin variable
for (int i = 0; i <=1; i++) { // for the first two bytes (i.e. 0 and 1)
incomingByte = Serial.read(); // read byte
Serial.println(incomingByte,DEC); // print what was read
LEDpin = LEDpin * 10 + (incomingByte - 48); // assemble full 2-digit integer
};
Serial.print("Lighting up LED #"); // Display which LED will be lit
Serial.println(LEDpin);
digitalWrite(LEDpin,HIGH); // Light up LED
while (Serial.available()) {
incomingByte = Serial.read(); // clear the buffer
}
}
}
It all works really well, but here's my question. If I comment out the line
Serial.println(incomingByte,DEC); // print what was read
it doesn't work anymore....
What does this line do besides print the byte values out to screen? Does it somehow change the type of incomingByte?
Thanks for your help.