Any ideas on how to play audio while concurrently updating an LCD?

I made a digital clock that has an alarm function. When the hours and minutes match the time stored as an alarm, a call is made to a function that plays a simple tone for 20 seconds. I'm using the tone library. The only problem is that while the tone is playing, the LCD stops updating. The seconds on my clock then jump to :20 and resume ticking when the audio finishes. I know why it does this. The atmega328 can only do one thing at a time. Once I leave the main loop that's updating the LCD to play the audio, updates to the LCD are stopped. It then resumes once the audio finishes and the code returns to the main loop.

If I had hours and minutes on the LCD, you'd be none the wiser that the screen is frozen during audio playback, but with seconds on the display, it's pretty obvious.

So my question is, is there a way to get around this? I can't think of a way to play the audio and keep the time running on the LCD.

Perhaps add a real time clock chip to handle keeping track of time and using it to trigger the alarm as an interrupt?

These RTC's are available on breakout boards with support libraries so integrating one wouldn't be difficult.

or you could use more than one arduino.

a call is made to a function that plays a simple tone for 20 seconds.

Let's see the code. tone() is non-blocking, so you are doing something less than optimal (otherwise known as wrong).

PaulS:
... you are doing something less than optimal (otherwise known as wrong).

Less than optimal == wrong.
Far less than optimal == very wrong.
Non-optimal == damn stupid. :slight_smile: