Hi everyone,
I am creating a project using the musical instrument shield along with flex sensors, and the project idea is to design a glove that plays certain notes depending on the degree the finger is bent, imitating hitting notes on a piano/keyboard.
I have been trying to make each flex sensor correspond to a specific note, but the sparkfun musical instrument shield doesn't seem to be responding even though all of the flex sensors are reading values. Is anyone familiar with the program and would be able to help? That would be highly appreciated!
Below is the code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
byte note = 0; //The MIDI note value to be played
byte resetMIDI = 4; //Tied to VS1053 Reset line
byte ledPin = 13; //MIDI traffic inidicator
int instrument = 12;
int flexpin1 = A12;
int flexpin2 = A11, flexpin3 = A12, flexpin4 = A13, flexpin5 = A14;
void setup() {
Serial.begin(57600); //Setup soft serial for MIDI control
mySerial.begin(31250);
talkMIDI(0xB0, 0, 0x79); //Bank select Melodic
talkMIDI(0xC0, 12, 0); //Set instrument number.
}
void loop() {
int flexVal1 = analogRead(flexpin1);
Serial.print("Sensor1: ");
Serial.println(flexVal1);
if (digitalRead(flexVal1) < 250) {
noteOn(0, 27, 60);
//delay(50);
} else {
noteOff(0, 27, 60);
// delay(50);
}
}
//Send a MIDI note-on message. Like pressing a piano key
//channel ranges from 0-15
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) {
digitalWrite(ledPin, HIGH);
mySerial.write(cmd);
mySerial.write(data1);
}
/* int flexVal2;
flexVal2 = analogRead(flexpin2);
Serial.print("Sensor2: ");
Serial.println(flexVal2);
int flexVal3;
flexVal3 = analogRead(flexpin3);
Serial.print("Sensor3: ");
Serial.println(flexVal3);
int flexVal4;
flexVal4 = analogRead(flexpin4);
Serial.print("Sensor4: ");
Serial.println(flexVal4);
int flexVal5;
flexVal5 = analogRead(flexpin5);
Serial.print("Sensor5: ");
Serial.println(flexVal5);
*/