Hello, perhaps it's the right thing!
What is to do? Combine ?
Like this or is something to change?
#include <Button.h>
#include <MIDI.h>
#define DEBOUNCE 1500
struct key
{
int pin;
int midiKey;
int debounce;
};
struct key keys[] =
{
{ 22, 25, 0 }, // Db red
{ 24, 26, 0 }, // D red
{ 26, 27, 0 }, // Eb orange
{ 28, 28, 0 }, // E orange
{ 30, 29, 0 }, // F yellow
{ 32, 30, 0 }, // Gb green
{ 34, 31, 0 }, // G green
{ 36, 32, 0 }, // Ab blue
{ 38, 33, 0 }, // A blue
{ 40, 34, 0 }, // Bb violet
{ 42, 35, 0 }, // B violet
{ 44, 36, 0 }, // C brown
{ 48, 24, 0 }, // C brown
{ 0, 0, 0 } // end of list marker
};
int keyOffset = 0;
void setup() {
// put your setup code here, to run once:
for(int i = 0; keys*.pin != 0; ++i)*
- {*
pinMode(keys*.pin, INPUT_PULLUP);
_ }_
_ Serial.begin(9600); // set up Serial library at 9600 bps*_
* Serial.println("Setup complete");*
}
void noteOn(int midiKey)
{
* Serial.print("Note On: ");*
* Serial.println(midiKey);*
}
void noteOff(int midiKey)
{
* Serial.print("Note Off: ");*
* Serial.println(midiKey);*
}
void loop() {
* // put your main code here, to run repeatedly:*
* int value;*
_ for(int i = 0; keys*.pin != 0; ++i)
{
value = digitalRead(keys.pin);
if(keys.debounce == 0) // Key has been off*
* {
if(value == LOW) // Key is now on*
* {
noteOn(keys.midiKey); // Send the MIDI note on message*
keys*.debounce = DEBOUNCE; // Set the note off debounce counter*
* }
}
else // Key has been on*
* {
if(value == HIGH) // Key has gone off*
* {
if(--keys.debounce == 0) // If Key has remained off for DEBOUNCE scans,
noteOff(keys.midiKey);
}
else // Key has not gone off*
keys*.debounce = DEBOUNCE; // Reset debounce counter in case we got*
* // a small number of key off scans*
* }
}
}*_