From 5f0dbc2e23b2267b556b5b7759298f708aef62fd Mon Sep 17 00:00:00 2001 From: Vineet K Date: Sun, 21 Apr 2024 21:46:20 -0400 Subject: [PATCH] bypass _delay_ms and user timer instead for silent note --- notes.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/notes.c b/notes.c index 44b24c0..8d082ad 100644 --- a/notes.c +++ b/notes.c @@ -196,7 +196,19 @@ play_note(unsigned char _note, unsigned short _cycles) for (unsigned short i = 0; i < _cycles; i++) playtone(); } else { - _delay_ms(_cycles); + // when note is 255, don't play anything for _cycles ms + // Prepare Timer/Counter + TCNT1 = 1; + OCR1A = 16e3 * _cycles / T1_PRESCALAR; + TCCR1B |= 1 << CS11; + + // Monitor OutPut Compare Flag + while ((TIFR1 & (1 << OCF1A)) == 0); + + // Toggles port For Speaker + PORTD ^= 1 << P_SPKR; + TIFR1 |= 1 << OCF1A; + TCCR1B &= ~(1 << CS11); } }