I want to make a portable 36-key polyphonic piano.
I have a 5x8 matrix piano keyboard(with diodes) that I want to be able to play chords on (simultaneous key press). I have made some tweaks to the example from Mark Stanley found here and I am trying to implement the tone function so that each key outputs its corresponding tone. I am not sure how to assign a tone to each key and then output those tones to analog input 6(external speaker).
I commented out the section where I believe I need help
#include <Keypad.h>
#include "pitches.h"
const byte ROWS = 5;
const byte COLS = 8;
char keys[ROWS][COLS] = {
{'1','2','3','4','5','6','7','8'},
{'A','B','C','D','E','F','G','H'},
{'I','J','K','L','M','N','O','P'},
{'Q','R','S','T','U','V','W','X'},
{'Y','Z','!','@','#','
Any help is greatly appreciated
I also included a code I wrote that doesnt use keypad.h and only outputs one tone at a time(Piano3)
edit: I included the original file plus the pitches library that im trying to implement
pitches.h (1.95 KB)
PortablePiano.ino (1.9 KB)
Piano3.ino (5.84 KB),'%','&'},
};
byte rowPins[ROWS] = {A0, A1, A2, A3, A4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 3, 4, 5, 6, 7, 8, 9}; //connect to the column pinouts of the keypad
Keypad kpd = Keypad( makeKeymap (keys), rowPins, colPins, ROWS, COLS );
unsigned long loopCount;
unsigned long startTime;
String msg;
void setup() {
Serial.begin(9600);
loopCount = 0;
startTime = millis();
msg = "";
}
void loop () {
loopCount++;
if((millis()-startTime)>5000) {
Serial.print("Average loops per second =");
Serial.println(loopCount/5);
startTime = millis();
loopCount = 0;
}
// Fills kpd.key[ ] array with up-to 10 active keys.
// Returns true if there are ANY active keys.
if (kpd.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
{
if ( kpd.key[i].stateChanged ) // Only find keys that have changed state.
{
/*
switch (kpd.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED:
msg = " PRESSED.";
break;
case HOLD:
msg = " HOLD.";
break;
case RELEASED:
msg = " RELEASED.";
break;
case IDLE:
msg = " IDLE.";
}
Serial.print("Key ");
Serial.print(kpd.key[i].kchar);
Serial.println(msg);
*/
}
}
}
} // End loop
Any help is greatly appreciated
I also included a code I wrote that doesnt use keypad.h and only outputs one tone at a time(Piano3)
edit: I included the original file plus the pitches library that im trying to implement
[pitches.h|attachment](upload://jInj0aptVfSNffSCEQEo7xWHvYh.h) (1.95 KB)
[PortablePiano.ino|attachment](upload://qJug2bL5Ck41vE2PkYdUHuPN0VZ.ino) (1.9 KB)
[Piano3.ino|attachment](upload://qzkZL5lU5jtUiJO6i4DunNKdIqT.ino) (5.84 KB)