# Multiple LED over Serial communication with Arduino

Several LEDs are being driven by Arduino. The LEDs to be lit up are sent to Arduino over serial port. When Arduino receives 12H\n over serial, it will execute digitalWrite(12, HIGH). Then the buffer is flushed. And before executing the write, all other output pins are set to LOW.

Question: \n is currently used to indicate the end of a LED pin number for a single pin. How would you label the end of a sequence of LEDs that should be lit up at a time? Eg: 7H 13H 11H\t? Or 7H,13H,11H\n? Is there a best practice?

How will you parse it with Arduino?

## 1 Answer

You are the author of your particular embedded program, so you can pick whatever you want the sequence to be. Obviously if you're working for a company or in a team, you should arrive at a choice unanimously.

If you are only ever going to control 12 LED's, you could pick 13H as the "end" of group*. You could also pick 99H, or the tab or newline character.

What future commands might you implement? Different commands to indicate the LED's should chase, sequence, fade in, or some other effect? Plan your serial commands accordingly, leaving some to future implementations, as best you can. But don't get carried away - some programmers spend too much time planning for features that may never happen.

*Assuming that LED #1 is 01H and "all off" is 00H or something.

• Like implementing some embedded form of SMIL. – Ignacio Vazquez-Abrams Sep 21 '13 at 4:27