mirror of
https://codeberg.org/eel4746_piano/avr_piano.git
synced 2024-11-22 09:10:30 -05:00
connect all 15 buttons to notes arduino
This commit is contained in:
parent
e16ce44563
commit
7eb9db0d82
20
notes.c
20
notes.c
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* EEL4746C - AVR Piano - Speaker Section
|
* EEL4746C - AVR Piano - Speaker Section
|
||||||
* speaker is connected to PD2 and ground
|
* speaker is connected to PD2 and ground
|
||||||
* buttons are connceted to PB0-5, PC0-5, PD3-7
|
* 15 buttons are connected to PD3-7, PC0-4, PB0-4
|
||||||
* the LCD Arduino UNO is connected to TX/RX (PD0/1)
|
* the LCD Arduino UNO is connected to TX/RX (PD0/1)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -37,6 +37,7 @@ unsigned short freqs[] = {
|
|||||||
FREQ(6000),
|
FREQ(6000),
|
||||||
FREQ(7000),
|
FREQ(7000),
|
||||||
FREQ(8000),
|
FREQ(8000),
|
||||||
|
[255] = 0 // used as a 'silent' note
|
||||||
};
|
};
|
||||||
unsigned char note = 0;
|
unsigned char note = 0;
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ ISR (PCINT0_vect)
|
|||||||
// check if any button in the whole port is pressed
|
// check if any button in the whole port is pressed
|
||||||
for (unsigned char i = 0; i <= 5; i++) {
|
for (unsigned char i = 0; i <= 5; i++) {
|
||||||
if (PINB & (1 << i)) {
|
if (PINB & (1 << i)) {
|
||||||
note = i + 5 + 6;
|
note = i + 5;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,7 +57,7 @@ ISR (PCINT1_vect)
|
|||||||
// check if any button in the whole port is pressed
|
// check if any button in the whole port is pressed
|
||||||
for (unsigned char i = 0; i <= 5; i++) {
|
for (unsigned char i = 0; i <= 5; i++) {
|
||||||
if (PINC & (1 << i)) {
|
if (PINC & (1 << i)) {
|
||||||
note = i + 5;
|
note = i + 5 + 6;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,7 +68,7 @@ ISR (PCINT2_vect)
|
|||||||
// check if any button in the whole port is pressed
|
// check if any button in the whole port is pressed
|
||||||
for (unsigned char i = 3; i <= 7; i++) {
|
for (unsigned char i = 3; i <= 7; i++) {
|
||||||
if (PIND & (1 << i)) {
|
if (PIND & (1 << i)) {
|
||||||
note = i;
|
note = i - 3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,11 +83,10 @@ main(void)
|
|||||||
DDRD = (1 << P_TX) | (1 << P_SPKR);
|
DDRD = (1 << P_TX) | (1 << P_SPKR);
|
||||||
|
|
||||||
// Enabling Pin Change Interrupt for All Buttons
|
// Enabling Pin Change Interrupt for All Buttons
|
||||||
PCMSK0 = 0b00111111;
|
PCMSK0 = 0b00011111;
|
||||||
PCMSK1 = 0b00111111;
|
PCMSK1 = 0b00011111;
|
||||||
PCMSK2 = 0b11111000;
|
PCMSK2 = 0b11111000;
|
||||||
// PCICR = (1 << PCIE0) | (1 << PCIE1) | (1 << PCIE2);
|
PCICR = (1 << PCIE0) | (1 << PCIE1) | (1 << PCIE2);
|
||||||
PCICR = 1 << PCIE2;
|
|
||||||
|
|
||||||
TCCR1A = 0x00; // use timer1 CTC mode
|
TCCR1A = 0x00; // use timer1 CTC mode
|
||||||
TCCR1B = 1 << WGM12; // already prescaled by 8 in table
|
TCCR1B = 1 << WGM12; // already prescaled by 8 in table
|
||||||
@ -95,8 +95,8 @@ main(void)
|
|||||||
|
|
||||||
// Sends Square wave to the Speaker When a Button is Pressed
|
// Sends Square wave to the Speaker When a Button is Pressed
|
||||||
for (unsigned char n = 0;; n = (n + 1) % 2) {
|
for (unsigned char n = 0;; n = (n + 1) % 2) {
|
||||||
//if (((PIND & 0b11111000) | (PINC & 0b00111111) | (PINB & 0b00111111)) == 0)
|
// check if any buttons are pressed, otherwise don't play a note
|
||||||
if ((PIND & 0b11111000) == 0)
|
if (((PINB & PCMSK0) | (PINC & PCMSK1) | (PIND & PCMSK2)) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Prepare Timer/Counter
|
// Prepare Timer/Counter
|
||||||
|
Loading…
Reference in New Issue
Block a user