The following, is freaking sweet:
Both of these are pretty simple bits of code, trivial really, but look at what's happening here.
My Arduino board is talking to Pure Data. Not only that, but it's doing so in a tidy, scalable way. Here's how it works:
The Arduino program waits to see a character (any character) appear on the COM port. When it gets one, it waits 10ms and sends one byte, then another 10ms and sends another one. I've made them have different behavior so I could tell them apart for debug, but they could be anything.
The Pure Data side sends a random number to the COM port when you click the top bang. Doing this also resets the packet counter on the right. Each received byte increments the packet counter, which is then used with my crude routing spigots below, so that each byte is allocated, in sequence, where it belongs.
If I did a long list of sends (say, one for each potentiometer on a nice big loaderboard) from the 'duino, it could sort these too. I can now build arbitrary input hardware to talk to Pure Data. How sweet is that.
Get the Pure Data Patch
Get the Arduino Code