diff options
| -rw-r--r-- | notes.c | 14 |
1 files changed, 13 insertions, 1 deletions
| @@ -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 | ||
