hello,
How can a write a simple program using usart of arduino.I want a program where in if i press 1 on the serial monitor i shd pass high to led 13 and if 2 pressed the led shd go off and when 3 is pressed i want the LED to toggle.
There is a SoftSerial class:
(maybe u have to vary the baud rate a little... +/- 10%) :![]()
U could do it urself... with fast direct port manipulation:
-arne
No reason not to use the hardware serial class/hardware serial port.
#define ledPin 13
void loop()
{
if(Serial.available() > 0) // Is there any data to read?
{
char aChar = Serial.read(); // Read a character
if(aChar == 'H' || aChar == 'h')
{
digitalWrite(ledPin, HIGH);
}
else if(aChar == 'L' || aChar == 'l')
{
digitalWrite(ledPin, LOW);
}
}
}
This code would allow you to send H (or h) to turn the LED on. Send L (or l) to turn it off.
Change H to 1, and L to 2, if you prefer to use numbers.
Add another if test (aChar == T or aChar == 3) to toggle the LED. If you are going to do that, you need to keep track of whether the LED is currently on or off, and set it correctly in all 3 blocks.
i tried the code given ,but it dint work out.I replaced them with aisc characters also,still could not get the required output.
what did u use in the function setup()?
there should be something like Serial.begin(9600) or so...
u could just toggle the LED whenever a character is read... no matter what character it was...
-arne