add untested pin change interrupts for note buttons

This commit is contained in:
Vineet K 2024-04-17 20:06:31 -04:00 committed by Shokara Kou
parent f5713538fe
commit 3808c19de4

43
notes.c
View File

@ -1,6 +1,7 @@
/* /*
* EEL4746C - AVR Piano - Speaker Section * 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) * the LCD Arduino UNO is connected to TX/RX (PD0/1)
*/ */
@ -37,8 +38,8 @@ unsigned short freqs[] = {
FREQ(7000), FREQ(7000),
FREQ(8000), FREQ(8000),
}; };
unsigned char note = 8; unsigned char note = 0;
unsigned char buttonpressed = 1; unsigned char buttonpressed = 0;
int int
main(void) main(void)
@ -79,15 +80,51 @@ main(void)
ISR (PCINT0_vect) 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) 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) 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;
}
}
} }