From 9f6c3500159cd828d633345d1fb39250b4e5669b Mon Sep 17 00:00:00 2001 From: Joseph Bryant Date: Wed, 17 Apr 2024 15:26:01 -0400 Subject: [PATCH] Comments for Notes.c --- notes.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/notes.c b/notes.c index 448d7f7..dbbca44 100644 --- a/notes.c +++ b/notes.c @@ -1,7 +1,6 @@ /* * EEL4746C - AVR Piano - Speaker Section - * speaker is connected to PD2 and ground -, PD3-7 + * speaker is connected to PD2 and ground, PD3-7 * the LCD Arduino UNO is connected to TX/RX (PD0/1) */ @@ -42,12 +41,14 @@ unsigned char note = 8; unsigned char buttonpressed = 1; int -main(void) +main(void) { + // Data Direction for Buttons, UART, Speaker DDRB = 0x00; DDRC = 0x00; - DDRD = (1 << P_TX) | (1 << P_SPKR); + DDRD = (1 << P_TX) | (1 << P_SPKR); + // Enabling Pin Change Interrupt for All Buttons PCMSK0 = 0xFF; PCMSK1 = 0xFF; PCMSK2 = ~(1 | (1 << 1) | (1 << 2)); @@ -58,16 +59,18 @@ main(void) sei(); - //for (;;); + // Sends Square wave to the Speaker When a Button is Pressed for (unsigned char n = 0;; n = (n + 1) % 2) { if (!buttonpressed && n == 0) continue; - + + // Prepare Timer/Counter TCNT1 = 1; OCR1A = freqs[note]; TCCR1B |= 1 << CS11; - while ((TIFR1 & (1 << OCF1A)) == 0); + while ((TIFR1 & (1 << OCF1A)) == 0); // Monitor OutPut Compare Flag + // Toggles port For Speaker PORTD ^= 1 << P_SPKR; TIFR1 |= 1 << OCF1A; TCCR1B &= ~(1 << CS11);