Hi!
I'm new to arduino and also don't know much about MIDI either, i know about analogue electronics but not much about digital, i found a few days ago this project and decided to give it a try in order to make a one octave keyboard to play with my feet (like the moog taurus, can't waint to jam some Rush)
this is the link:
Added a line in the begining to start the MIDI to the original code in order to make it work with the most recent library, mounted everything in a protoboard just like in the schematic, all 12 keys work and the synth plays the notes, but can't make work the octave up/down buttons or the pitch bend, also neither serial plotter, serial monitor display anything when said buttons are pressed
Any suggestion? I'd really appreciate it
/*
This sketch is based on example code from ADAFRUIT (Thanks a lot!)
http://www.adafruit.com/blog/2009/10/20/example-code-for-multi-button-checker-with-debouncing/
and uses MIDI library:
http://sourceforge.net/projects/arduinomidilib/
*/
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
#define DEBOUNCE 10 // button debouncer, how many ms to debounce, 5+ ms is usually plenty
// here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etc
byte buttons[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; // the analog 0-5 pins are also known as 14-19
// This handy macro lets us determine how big the array up above is, by checking the size
#define NUMBUTTONS sizeof(buttons)
// we will track if a button is just pressed, just released, or 'currently pressed'
byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];
void setup() {
MIDI.begin(1); // Launch MIDI with default options
byte i;
// pin13 LED
pinMode(13, OUTPUT);
// Make input & enable pull-up resistors on switch pins
for (i=0; i< NUMBUTTONS; i++) {
pinMode(buttons[i], INPUT);
digitalWrite(buttons[i], HIGH);
}
}
void check_switches()
{
static byte previousstate[NUMBUTTONS];
static byte currentstate[NUMBUTTONS];
static long lasttime;
byte index;
if (millis() < lasttime) {
// we wrapped around, lets just try again
lasttime = millis();
}
if ((lasttime + DEBOUNCE) > millis()) {
// not enough time has passed to debounce
return;
}
// ok we have waited DEBOUNCE milliseconds, lets reset the timer
lasttime = millis();
for (index = 0; index < NUMBUTTONS; index++) {
justpressed[index] = 0; // when we start, we clear out the "just" indicators
justreleased[index] = 0;
currentstate[index] = digitalRead(buttons[index]); // read the button
if (currentstate[index] == previousstate[index]) {
if ((pressed[index] == LOW) && (currentstate[index] == LOW)) {
// just pressed
justpressed[index] = 1;
}
else if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
// just released
justreleased[index] = 1;
}
pressed[index] = !currentstate[index]; // remember, digital HIGH means NOT pressed
}
//Serial.println(pressed[index], DEC);
previousstate[index] = currentstate[index]; // keep a running tally of the buttons
}
}
void loop() {
check_switches(); // when we check the switches we'll get the current state
for (byte i = 0; i < NUMBUTTONS; i++) {
if (justpressed[i]) {
MIDI.sendNoteOn(44+i,127,1);
}
if (justreleased[i]) {
MIDI.sendNoteOff(44+i,127,1);
}
}
}