summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVineet K <git@vineetk.net>2024-04-21 21:46:20 -0400
committerShokara Kou <kou@13f0.net>2024-04-21 21:46:20 -0400
commit5f0dbc2e23b2267b556b5b7759298f708aef62fd (patch)
tree625582bc97d07c5b42ea64e535fa5bd5189924fa
parentece65dcc2a11b6f22eed9ce583075f82ca177064 (diff)
bypass _delay_ms and user timer instead for silent note
-rw-r--r--notes.c14
1 files changed, 13 insertions, 1 deletions
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)
196 for (unsigned short i = 0; i < _cycles; i++) 196 for (unsigned short i = 0; i < _cycles; i++)
197 playtone(); 197 playtone();
198 } else { 198 } else {
199 _delay_ms(_cycles); 199 // when note is 255, don't play anything for _cycles ms
200 // Prepare Timer/Counter
201 TCNT1 = 1;
202 OCR1A = 16e3 * _cycles / T1_PRESCALAR;
203 TCCR1B |= 1 << CS11;
204
205 // Monitor OutPut Compare Flag
206 while ((TIFR1 & (1 << OCF1A)) == 0);
207
208 // Toggles port For Speaker
209 PORTD ^= 1 << P_SPKR;
210 TIFR1 |= 1 << OCF1A;
211 TCCR1B &= ~(1 << CS11);
200 } 212 }
201} 213}
202 214