commit 3808c19de4ced0a834341564f3b24cd21de59311
parent f5713538fe12b57c286188a2bf13016628f55a92
Author: Vineet K <git@vineetk.net>
Date: Wed, 17 Apr 2024 20:06:31 -0400
add untested pin change interrupts for note buttons
Diffstat:
| M | notes.c | | | 49 | +++++++++++++++++++++++++++++++++++++++++++------ |
1 file changed, 43 insertions(+), 6 deletions(-)
diff --git 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;
+ }
+ }
}