commit 9f6c3500159cd828d633345d1fb39250b4e5669b
parent d4d4114b316ff262024119925577915e4b5d75d9
Author: Joseph Bryant <jbryant0653@floridapoly.edu>
Date: Wed, 17 Apr 2024 15:26:01 -0400
Comments for Notes.c
Diffstat:
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git 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);