I need to add async music playing with buzzer to my ESP32 project, but I can't understand how to properly restart timer with required characteristics during interrupt.
The initial idea is next. I have some Sound structure, what contains array of Notes, where each note has length and tone.
To play Sound I use tone() function in interrupts. Using Note.tone I control frequency and using interrupt length I control time during what note is played.
So, in interrupt I have to do next:
- Get current note
- Start playing note using tone()
- Stop timer
- Set timer to create next interrupt in Note.length milliseconds.
- Start timer again.
- Exit interrupt.
Instead, it plays first note and freezes on second. I am developing project in simulation environment, so here is link for project. Related code is on lines 24 - 68, 184 - 232 and 1651 - 1672
Does anybody know what I did wrong here? I was following https://docs.espressif.com/projects/arduino-esp32/en/latest/api/timer.html during development, and if I correctly understood it, everything had to be okay, but by some reason, it isn't. What I did wrong?