I send sentences with the structure of "<command,data,data,data>" I set the Serial receiver to ignore all the incoming until it gets a sentence start. At sentence start I place the incoming into a buffer till a >, end of sentence, is received. I then send the received packet onto a parser.
Any code that does the job is good code! Maybe implementing different codes for different messages could be interesting. Store the different codes in an array and use the index into the array to select message!
So if the receiver starts receiving TERNPAT because a start point has not been designated.
If a structured message like "<bilnk,blink,notblink,notblink,blink>" is sent then not until a < is received will the receiver function start storing or buffering the incoming message. Then when a > is received the full message properly formatted in the correct order has been receivved.
I hope that helps if not do a search on the site for "serial input basics."
Ok I now understand better. In my case, there's no serial involved and no need for a start pattern. Maybe a quick and short blinking pattern could be use to signal the end of the pattern so the user don't misinterpret 2-5 for 5-2.
What I’ve done in the past, is implement a timed block sequence . e.g. 16 slots per message block, would allow a 4 flash set (possible 4 on, with 4 off slots per message, = 8 slots plus the 8-slot ‘off’ gap between messages.
This can be stored in an unsigned 16-bit integer, and shifted out with a simple function.
I did it with two colour LEDs (red & green, two ints), so 2^3 * 3 colours == 48 unique codes.
e.g. Red off Green off Red off Yellow off, followed by 8 ‘off’ slots as a spacer, then repeat as necessary.
Of course, this can be simplified to a single colour.
Blink speed is up to you.
You can also do other things like set all slots on, to get the user’s attention, then blink out the sequence.
Remember to make the blink sequencer non-blocking, so your main code can keep doing what it’s doing.
Think of using a multidimensional array. At index 1 there is one message. At index 2 there's an other message. That way You only need one function to send 2 different messages.
In psedocode:
Delare
int messageArray[nrOfMessages, messageLenght];
Traditionally this would be "Morse" code or International Morse Code which uses four symbols; a single length "mark" (called "dit"), a triple length "mark" (called "dah"), a single length "space" which separates marks in a character and a triple length "space" which separates different characters.
It is specifically designed to be human-readable. It makes sense to use this existing standard; you can assign the single letters (and numerals, which are longer) to a given message or code a complete message.