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); } }