I'm not sure if I understand right what you want to achieve. Shall the LED blink all the time?
What your code actually does is
whenever a character was received the condition
if (Serial.available() > 0)
becomes true and the code below this condition will be executed.
So whenever an "a" is received LED_pin is switched on for one second then switched off and your code waits another second until the code-execution goes on
whenever a "b" is received LED_pin2 is switched on for one second then switched off and your code waits another second until the code-execution goes on
This seems to be not what you want to achive. But what exactly do you want to achieve?
Can you describe what should happen instead?
Make 'Read' a static variable so it retains its value between calls to loop(). Change 'Read' only when a character is available. Select "No line ending" in Serial Monitor so a line ending character doesn't overwrite the last character sent.
I will give another example that I need to have it on.
I have a switch section and I need that when I send "r" to start flashing red all the time, then when I send "g" it starts flashing green, but all the time, it doesn't stop
dj_nejk:
I will give another example that I need to have it on.
I have a switch section and I need that when I send "r" to start flashing red all the time, then when I send "g" it starts flashing green, but all the time, it doesn't stop
The sketch in Reply #3 will repeat 'r', 'g', or 'b' just as easily as it repeats 'a' or 'b'. Just replace the contents of the 'switch' statement.
if (Serial.available())
{
char c = Serial.read();
// Only act on the characters we want. Ignore everything else.
if (c == 'r' || c == 'g' || c == 'b')
Read = c;
}