How do you read a serial input then just turn on an LED? been playing around with the arduino serial library and cannot seem to connect the dots. Any help is greatly appreciated
Well, if you just want to read serial data, and then turn on an LED, you could do something like this:
int ledPin = 13;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while(Serial.available() > 0)
{
char c = Serial.read();
}
digitalWrite(ledPin, HIGH);
}
On the other hand, if you want to base a decision on whether to turn the LED on or off, and which pin to use, on the data read from the serial port, that's a whole different story. You need to tell us more about what you want to do.
Trying to turn on an LED based off an input from the serial read, figured I would use 1 for high/ ON and 0 for low/OFF
Try this, then:
int ledPin = 13;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while(Serial.available() > 0)
{
char c = Serial.read();
if(c == '1')
digitalWrite(ledPin, HIGH);
else if(c == '0')
digitalWrite(ledPin, LOW);
}
}
Thank you for all your help, this has it working finally, now on to the next learning block. Thank you again.