Electronic – Synchronising two microcontrollers for LED sequence and piezo speaker

ledpicaxepiezosound

I am making a piano keyboard which has a subsystem that plays a song whilst lighting up the corresponding notes that are to be played.
I have used a PICAXE 20M2 microcontroller for the LED sequence and a PICAXE 18M2 with a piezo for the actual sound.

They work well separately, however I am struggling to get them to play together in time, as they are at different speeds.

Is there a way I can make them sync? Or is it literally a case of trial and error until they work?

Best Answer

Reading between the lines, I take it that you have programmed the same song into both microcontrollers, you reset them both, and each one "plays" the song on its own, one using light and the other using sound.

What you really need is a master-slave relationship, in which the song is only "playing" on one of the microcontrollers, and that one sends commands to the other whenever the note changes. For example, if the one with the LEDs is the master, each time it changes to the next note, it would send a command to the other one to play the sound frequency that corresonds to that note. The second microcontroller wouldn't have the actual song programmed into it at all, it would simply play tones based on commands from the master.

You might even consider using the MIDI protocol for the communications, since it was specifically designed for this sort of real-time performance data. In fact, you might go so far as to introduce a third microcontroller that does nothing but interpret the song data and produce the MIDI messages. Your two existing microcontrollers would then be modified to receive the MIDI messages and perform the corresponding actions, one with sound and the other with light. You would then be able to mix-and-match these building blocks with other MIDI-compatible equipment.