Synchronizing mono tone with LEDs

Status
Not open for further replies.

lloydi12345

Member
Hi ETO, I am building a christmas lantern using LEDs and I would like to add some tune with it. Do you have any idea how I could synchronize them? I am thinking about using 2 microcontrollers which will communicate through serial but is there any fancier way to do it? I am already done with tone and led patterns code but I don't know how to make them work together.

Thanks.

lloyd
 
If there is enough processing power left over the same PIC could flash the LEDs and make tone type music. I would do it that way, using the PIC PWM module to drive the LEDs and the PIC TMR0 interrupt to make the tone music.

Maybe you should post the code and schematic, that will make it easier to advise and other people too might like to make Christmas lanterns.
 
Thanks for the reply Mr Roman Black. I already generated tones like a "do re mi" sort of tune. The problem arises when an led pattern is quickly loaded that not a single tone could be played. The problem is about synchronizing them.

I am by the way using 4Mhz crystal oscillator for timing.

Is it possible to resume certain lines in microcontroller during interrupt? What I mean is for example I am playing a tune on the main routine while(1), then here comes the timer interrupt that will execute a single line in a sub-routine called "pattern" that will load the led's design or sequence. After executing that single line (of course because you can't execute all the routine inside an interrupt), it will go back to the main while(1) loop and continue playing the tone left and when the interrupt comes again, it will execute another single line (resume) but this time it is executing the second line in the sub-routine of "pattern" and again stop at the end of the line and go back to the sound. The process goes on and on. I hope you get what I mean.

Well, the schematic is just basic. Each LED is connected to each of the microcontroller pin so nothing new with it. Actually, I am planning to post everything here after I'm done building it. I really hope this project would be successful.
 
Last edited:
I think you need to draw a flowchart or something like that, and really decide on how the entire project operates.

If you just light one LED on one PIC pin, and then play a single note, that is very easy;
1. turn LED A on
2. play note A
3. turn LED A off
4. (delay between notes, if needed)

If you need to make multiple LEDs flash while a single note is playing, that is more complicated and will need more planning.

Maybe something like this;
1. the note is generated in a fast simple TMR0 interrupt, automatically controlled by a variable; note
2. The variable is set to the note to be played (say note A)
3. the code flashes LEDs as needed (using TMR1), while the note A is automatically playing in the TMR0 interrupt
4. when the LED flash sequence is finished, the variable note is set back to 0, so interrupt automatically stops playing the note.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…