bypass _delay_ms and user timer instead for silent note

This commit is contained in:
Vineet K 2024-04-21 21:46:20 -04:00 committed by Shokara Kou
parent ece65dcc2a
commit 5f0dbc2e23

14
notes.c
View File

@ -196,7 +196,19 @@ play_note(unsigned char _note, unsigned short _cycles)
for (unsigned short i = 0; i < _cycles; i++) for (unsigned short i = 0; i < _cycles; i++)
playtone(); playtone();
} else { } 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);
} }
} }