Showing posts with label Chiptunes. Show all posts
Showing posts with label Chiptunes. Show all posts

Thursday, February 25, 2021

Playing music and tones using a piezo buzzer - library for AVR microcontrollers using timer interrupt | ATmega328

This is a library for playing monophonic music using PWM and a piezoelectric buzzer. Monophonic means it can play only one note at a time. Regardless, it can produce some nice music. Optionally a led can be made to blink with the music rhythm.

Apart from playing songs it can also be used for tone generation useful in projects where audio indicators are needed.

All you need is a 16-bit timer that can be one of the following: timer1, timer3 and timer4 (provided that the microcontroller has them) and an 1ms interval interrupt where to place the main function. This is needed because the notes must have a certain duration.

Playing music and tones using a piezo buzzer - library for AVR microcontrollers using timer interrupt | ATmega328P, ATmega88

Playing music on a piezoelectric buzzer using PWM and a microcontroller