Hello world
After searching for hours a way to make a keyboard from Arduino and MI shield from sparkfun, and with the helps of few people, I finally get my program.
It will probably seems a bit simple for advanced users, but It was quite a lot of work for me to make it works as a beginner. I thought it could be great to save time for other beginners if I share this program in this topic, so here we go , but before, if advanced users have some suggestions to improve it, you are more than welcome to contact me as I'm waiting to learn more :
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //Soft TX on 3, we don't use RX in this code
int inputPins[] = {5,6,7,8,9,10,11,12,13};
int note[]={72,74,76,77,79,81,83,84,86};
int pinCount = 9;
int buttonState[9];
int lastButtonState[9];
byte resetMIDI = 4; //Tied to VS1053 Reset line
int instrument = 13;
void setup() {
//Setup soft serial for MIDI control
mySerial.begin(31250);
for(int i=0; i<pinCount; i++){
pinMode(inputPins_, OUTPUT);//pinMode(outputPins*, OUTPUT);_
_ digitalWrite(inputPins, LOW);// this enables the pull up resistors to reduce noise*
pinMode(inputPins*, INPUT);
}
//Reset the VS1053*
* digitalWrite(resetMIDI, LOW);
delay(100);
digitalWrite(resetMIDI, HIGH);
delay(100);*_
* talkMIDI(0xB0, 0x07, 126); //0xB0 is channel message, set channel volume to near max (127)*
* talkMIDI(0xB0, 0, 0x79); //Default bank GM1*
* talkMIDI(0xC0, instrument, 0); //Set instrument number. 0xC0 is a 1 data byte command*
}
void loop() {
for (int i=0; i<pinCount; i++){
buttonState = digitalRead(inputPins*);*
* delay(1);*
if (buttonState != lastButtonState*) { *
_ if (buttonState == HIGH) {
noteOn(0,note,100);
}_
* }*
lastButtonState = buttonState*;*
* }*
}
//Send a MIDI note-on message. Like Pressing a piano key
void noteOn(byte channel, byte note, byte attack_velocity) {
* talkMIDI( (0x90 | channel), note, attack_velocity);
_}
//Send a MIDI note-off message. Like releasing a piano key*
void noteOff(byte channel, byte note, byte release_velocity) {
* talkMIDI( (0x80 | channel), note, release_velocity);*
}
//Plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that data values are less than 127
void talkMIDI(byte cmd, byte data1, byte data2) {
* mySerial.write(cmd);
mySerial.write(data1);
//Some commands only have one data byte. All cmds less than 0xBn have 2 data bytes*
* //(sort of: http://253.ccarh.org/handout/midiprotocol/)
if( (cmd & 0xF0) <= 0xB0)
mySerial.write(data2);
}*
*Here is a link to see it working : - YouTube
I also wrote the program to have this keyboard working with the Touch pad shield from Sparkfun. If people are interested , don't hesitate to ask.
All the best,
Plankton.