commit 5f0dbc2e23b2267b556b5b7759298f708aef62fd parent ece65dcc2a11b6f22eed9ce583075f82ca177064 Author: Vineet K <git@vineetk.net> Date: Sun, 21 Apr 2024 21:46:20 -0400 bypass _delay_ms and user timer instead for silent note Diffstat:
| M | notes.c | | | 14 | +++++++++++++- |
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git 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); } }