Teensy 4.0 microcontroller

Hey everyone, I am Emmanuel Katto. I just joined this community.
I’m working on a project that involves using a Teensy 4.0 microcontroller to control a series of LEDs with a custom waveform. The waveform is generated using a simple audio file playback system, and I want to synchronize the LED timing with the audio signal.

Here’s the issue: the audio playback is causing the system to become desynchronized over time, with the LED timing drifting away from the original waveform. I’ve tried using a simple counter to generate the LED timing, but this isn’t reliable enough. What are some strategies or libraries that I could use to improve the synchronization and keep the LED timing accurate?

Thanks in advance!
Emmanuel Katto

This page helped me immensely to learn about timings in a microcontroller and how to manage timing dependent code. Real Time Counter and Integer Overflow - Lucky Resistor

1 Like

Thanks for sharing the page link.

Did I understand you well? do you want to start playback at a frequency derived from the audio length? is there anything preventing you from starting the LED sequence and the audio chunk playback at the same point in the code?

Is the audio digitized or in analog form? Are the LEDs “smart” (WS2811/2812 types). Why is audio playback desynchronizing the LEDs? You can probably mitigate synchronization problems by using interrupts and/or other non-blocking techniques, or using separate microcontrollers - tied to a common clock - for audio and video.