diff --git a/notes.c b/notes.c index dbbca44..e007672 100644 --- a/notes.c +++ b/notes.c @@ -1,6 +1,7 @@ /* * EEL4746C - AVR Piano - Speaker Section - * speaker is connected to PD2 and ground, PD3-7 + * speaker is connected to PD2 and ground + * buttons are connceted to PB0-5, PC0-5, PD3-7 * the LCD Arduino UNO is connected to TX/RX (PD0/1) */ @@ -37,8 +38,8 @@ unsigned short freqs[] = { FREQ(7000), FREQ(8000), }; -unsigned char note = 8; -unsigned char buttonpressed = 1; +unsigned char note = 0; +unsigned char buttonpressed = 0; int main(void) @@ -79,15 +80,51 @@ main(void) ISR (PCINT0_vect) { + // check if any button on any port is pressed + if (PINB | PINC | PIND) + buttonpressed = 1; + else + buttonpressed = 0; + // check if any button in the whole port is pressed + for (unsigned char i = 0; i <= 5; i++) { + if (PINB & (1 << i)) { + note = i; + break; + } + } } ISR (PCINT1_vect) { + // check if any button on any port is pressed + if (PINB | PINC | PIND) + buttonpressed = 1; + else + buttonpressed = 0; + // check if any button in the whole port is pressed + for (unsigned char i = 0; i <= 5; i++) { + if (PINC & (1 << i)) { + note = i; + break; + } + } } ISR (PCINT2_vect) { + // check if any button on any port is pressed + if (PINB | PINC | PIND) + buttonpressed = 1; + else + buttonpressed = 0; + // check if any button in the whole port is pressed + for (unsigned char i = 3; i <= 7; i++) { + if (PIND & (1 << i)) { + note = i; + break; + } + } }