diff options
| author | Joseph Bryant <jbryant0653@floridapoly.edu> | 2024-04-17 15:26:01 -0400 |
|---|---|---|
| committer | Joseph Bryant <jbryant0653@floridapoly.edu> | 2024-04-17 15:26:01 -0400 |
| commit | 9f6c3500159cd828d633345d1fb39250b4e5669b (patch) | |
| tree | ea3192da4037f734dcebea81c689c1186e0d40cd | |
| parent | d4d4114b316ff262024119925577915e4b5d75d9 (diff) | |
Comments for Notes.c
| -rw-r--r-- | notes.c | 17 |
1 files changed, 10 insertions, 7 deletions
| @@ -1,7 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * EEL4746C - AVR Piano - Speaker Section | 2 | * EEL4746C - AVR Piano - Speaker Section |
| 3 | * speaker is connected to PD2 and ground | 3 | * speaker is connected to PD2 and ground, PD3-7 |
| 4 | , PD3-7 | ||
| 5 | * the LCD Arduino UNO is connected to TX/RX (PD0/1) | 4 | * the LCD Arduino UNO is connected to TX/RX (PD0/1) |
| 6 | */ | 5 | */ |
| 7 | 6 | ||
| @@ -42,12 +41,14 @@ unsigned char note = 8; | |||
| 42 | unsigned char buttonpressed = 1; | 41 | unsigned char buttonpressed = 1; |
| 43 | 42 | ||
| 44 | int | 43 | int |
| 45 | main(void) | 44 | main(void) |
| 46 | { | 45 | { |
| 46 | // Data Direction for Buttons, UART, Speaker | ||
| 47 | DDRB = 0x00; | 47 | DDRB = 0x00; |
| 48 | DDRC = 0x00; | 48 | DDRC = 0x00; |
| 49 | DDRD = (1 << P_TX) | (1 << P_SPKR); | 49 | DDRD = (1 << P_TX) | (1 << P_SPKR); |
| 50 | 50 | ||
| 51 | // Enabling Pin Change Interrupt for All Buttons | ||
| 51 | PCMSK0 = 0xFF; | 52 | PCMSK0 = 0xFF; |
| 52 | PCMSK1 = 0xFF; | 53 | PCMSK1 = 0xFF; |
| 53 | PCMSK2 = ~(1 | (1 << 1) | (1 << 2)); | 54 | PCMSK2 = ~(1 | (1 << 1) | (1 << 2)); |
| @@ -58,16 +59,18 @@ main(void) | |||
| 58 | 59 | ||
| 59 | sei(); | 60 | sei(); |
| 60 | 61 | ||
| 61 | //for (;;); | 62 | // Sends Square wave to the Speaker When a Button is Pressed |
| 62 | for (unsigned char n = 0;; n = (n + 1) % 2) { | 63 | for (unsigned char n = 0;; n = (n + 1) % 2) { |
| 63 | if (!buttonpressed && n == 0) continue; | 64 | if (!buttonpressed && n == 0) continue; |
| 64 | 65 | ||
| 66 | // Prepare Timer/Counter | ||
| 65 | TCNT1 = 1; | 67 | TCNT1 = 1; |
| 66 | OCR1A = freqs[note]; | 68 | OCR1A = freqs[note]; |
| 67 | TCCR1B |= 1 << CS11; | 69 | TCCR1B |= 1 << CS11; |
| 68 | 70 | ||
| 69 | while ((TIFR1 & (1 << OCF1A)) == 0); | 71 | while ((TIFR1 & (1 << OCF1A)) == 0); // Monitor OutPut Compare Flag |
| 70 | 72 | ||
| 73 | // Toggles port For Speaker | ||
| 71 | PORTD ^= 1 << P_SPKR; | 74 | PORTD ^= 1 << P_SPKR; |
| 72 | TIFR1 |= 1 << OCF1A; | 75 | TIFR1 |= 1 << OCF1A; |
| 73 | TCCR1B &= ~(1 << CS11); | 76 | TCCR1B &= ~(1 << CS11); |
