summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--notes.c49
1 files changed, 43 insertions, 6 deletions
diff --git a/notes.c b/notes.c
index dbbca44..e007672 100644
--- a/notes.c
+++ b/notes.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * EEL4746C - AVR Piano - Speaker Section 2 * EEL4746C - AVR Piano - Speaker Section
3 * speaker is connected to PD2 and ground, PD3-7 3 * speaker is connected to PD2 and ground
4 * buttons are connceted to PB0-5, PC0-5, PD3-7
4 * the LCD Arduino UNO is connected to TX/RX (PD0/1) 5 * the LCD Arduino UNO is connected to TX/RX (PD0/1)
5 */ 6 */
6 7
@@ -37,8 +38,8 @@ unsigned short freqs[] = {
37 FREQ(7000), 38 FREQ(7000),
38 FREQ(8000), 39 FREQ(8000),
39}; 40};
40unsigned char note = 8; 41unsigned char note = 0;
41unsigned char buttonpressed = 1; 42unsigned char buttonpressed = 0;
42 43
43int 44int
44main(void) 45main(void)
@@ -79,15 +80,51 @@ main(void)
79 80
80ISR (PCINT0_vect) 81ISR (PCINT0_vect)
81{ 82{
82 83 // check if any button on any port is pressed
84 if (PINB | PINC | PIND)
85 buttonpressed = 1;
86 else
87 buttonpressed = 0;
88
89 // check if any button in the whole port is pressed
90 for (unsigned char i = 0; i <= 5; i++) {
91 if (PINB & (1 << i)) {
92 note = i;
93 break;
94 }
95 }
83} 96}
84 97
85ISR (PCINT1_vect) 98ISR (PCINT1_vect)
86{ 99{
87 100 // check if any button on any port is pressed
101 if (PINB | PINC | PIND)
102 buttonpressed = 1;
103 else
104 buttonpressed = 0;
105
106 // check if any button in the whole port is pressed
107 for (unsigned char i = 0; i <= 5; i++) {
108 if (PINC & (1 << i)) {
109 note = i;
110 break;
111 }
112 }
88} 113}
89 114
90ISR (PCINT2_vect) 115ISR (PCINT2_vect)
91{ 116{
92 117 // check if any button on any port is pressed
118 if (PINB | PINC | PIND)
119 buttonpressed = 1;
120 else
121 buttonpressed = 0;
122
123 // check if any button in the whole port is pressed
124 for (unsigned char i = 3; i <= 7; i++) {
125 if (PIND & (1 << i)) {
126 note = i;
127 break;
128 }
129 }
93} 130}