NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » Multiple Music Buzzers

March 07, 2011
by coderedave
coderedave's Avatar

Hello All,

I purchased my NerdKit a couple of weeks ago and I'm having a blast learning new things. Right now the project I have in mind is creating music using multiple piezoelectric buzzers to produce music that a piano or even music that a small band would play.

I have been messing around with the music box example given here and I pretty much understand it fully. The thing that I am wondering is, is it possible to have two different buzzers play at the same time? I know you can put them on two different pins and change them accordingly. But can you have the MCU process them simultaneously, such as using theads? Or is that even possible with an MCU?

Any help would be well received. Thanks.


March 10, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Dave,

The word "simultaneous" is a tricky thing when you are talking about computers. Even on your PC with threads, the operating system is context switching between processes and threads, and only one thing is ever currently happening on the CPU itself (on single core processors). On you MCU things are a bit trickier because there is no OS to switch back and forth between the things you are doing, so you only have one thread of operation. If you want to play two buzzers at the same time you will have to handle the time multiplexing between them in code.


March 16, 2011
by coderedave
coderedave's Avatar

Hey Humberto,

Thanks for the reply. Yeah threads perhaps wasn't a good word to choose. I was just throwing out something. Just had no idea how to go about doing it. Although after I've given a good deal of thought, I think I have an idea how to go about doing it. Right now I'm working on the led array kit and I think there are some concepts there that will help me with this one. So when I get done with that I'll focus back on this project. I will post what I figure out or having trouble with. I'm still open to any suggestions or ideas from anyone, so feel free to post them.

Thanks, David

March 16, 2011
by bretm
bretm's Avatar

This is a somewhat misleading. It implies that the microcontroller can't do threads while a PC's microprocessor can. A small OS can be installed on a microcontroller, and that OS can do threads and handle context switching between threads in the same manner that a more complex microprocessor can. It can do preemptive multitasking.

The essential difference is that on a large microprocessor the overhead for context switching is worthwhile, and the instruction set often includes native instructions that facilitate it. On a microcontroller the size of the Atmega168 the overhead is rarely worth it. The software is unlikely to be complex enough to need it. But the difference is quantitative (number of cores, clock speed, etc.), not qualitative.

Post a Reply

Please log in to post a reply.

Did you know that our USB NerdKit works on Windows, Linux, and Mac OS X? Learn more...