Hi guys i was hoping you could help us out, we have a project which uses LDR’s on a set of gloves to controll midi. Its mostly working, we have the aurdino sending what we think are the right messages to serial when we trigger the LDR’s but hairless isnt interpreting the MIDI messages properly, instead its sending out a tone of random messages. I was hoping you guys could help us with what we’re doing wrong, Its part of a University project and any help would be greatly appreciated, heres the code:
#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>
/* Codeist , Midi Gloves and Shoes,
Callan Marchetti , Sam Cocks , Conor Matheson */
/*This code sends MIDI messages using electrical pulses from FSRs (Force Sensitive Resistors) placed in the toes of shoes and also a resistance change using LDR's in a pair of gloves
It has been adapted from code by Thobson 'Midi Shoes'
/************************************************************/
// when the upper threshold is passed a hit is trigered and when the value sinks below the lower threshold another hit is triggered. "HYSTERESIS" makes sure multiple hits arent triggered
#define FINGERTHRESHOLD 400
#define LOWERFINGERTHRESHGHOLD 6
#define TOETHRESHOLD 350
#define LOWERTOETHRESHOLD 101 // We're setting both a lower and an upper threshold for the FSRs, so that they will only trigger a MIDI message when we actually want them too.
#define LHPOINTPIN 0
#define LHMIDPIN 1
#define LHRINGPIN 2
#define LHPINKYPIN 3
#define RHPINKYPIN 4
#define RHRINGPIN 5
#define RHMIDPIN 6
#define RHPOINTPIN 7
#define TOE1PIN 8
#define TOE2PIN 9
#define midichannel 0;
// Define which analog in pins on the arduino we'll be using
int pinNote[10] = {78,65,88,59,41,42,46,49,73,57}; // This array stores the different MIDI notes that each pin is assigned , do we need this?
boolean lhpoint = false;
boolean lhmid = false;
boolean lhring = false;
boolean lhpinky = false;
boolean rhpinky = false;
boolean rhring = false;
boolean rhmid = false;
boolean rhpoint = false;
boolean toe1 = false;
boolean toe2 = false; //These variables will help us to make sure we don't send multiple MIDI messages per single hit
void setup() {
MIDI.begin(1);
Serial.begin(57600);
} // We'll send debugging information to the Serial monitor
void loop(void) { // This is the main function that executes all the others.
lhpoint = sender((analogRead(LHPOINTPIN)+0), pinNote[LHPOINTPIN], lhpoint, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
lhmid = sender((analogRead(LHMIDPIN)+0), pinNote[LHMIDPIN], lhmid, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
lhring = sender((analogRead(LHRINGPIN)+0), pinNote[LHRINGPIN], lhring, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
lhpinky = sender((analogRead(LHPINKYPIN)+0), pinNote[LHPINKYPIN], lhpinky, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
rhpinky = sender((analogRead(RHPINKYPIN)+0), pinNote[RHPINKYPIN], rhpinky, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
rhring = sender((analogRead(RHRINGPIN)+0), pinNote[RHRINGPIN], rhring, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
rhmid = sender((analogRead(RHMIDPIN)+0), pinNote[RHMIDPIN], rhmid, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
rhpoint = sender((analogRead(RHPOINTPIN)+0), pinNote[RHPOINTPIN], rhpoint, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
toe1 = sender((analogRead(TOE1PIN)+0), pinNote[TOE1PIN], toe1, TOETHRESHOLD, LOWERTOETHRESHOLD);
toe2 = sender((analogRead(TOE2PIN)+0), pinNote[TOE2PIN], toe2, TOETHRESHOLD, LOWERTOETHRESHOLD);
}
void midimsg(unsigned char message, unsigned char pitch, unsigned char velocity) { // This function sends a MIDI message with a message, pitch, and velocity
Serial.write(message);
Serial.write(pitch);
Serial.write(velocity);
}
boolean sender(int reading, int note, boolean press, int threshold, int lowerthreshold ) { // This function is what does all the work
if(reading <= threshold) { // If the user stomps harder than a certain threshold...
if(!press) { // and if the sensor is not already in 'pressed' mode...
reading = reading/20 - 1; // convert the FSR reading to a MIDI-friendly value
midimsg(144, note, 128); // Send a MIDI message
// Send a unique debug message to the Serial monitor
delay(100);
} press = true; // The sensor is now in 'pressed' mode,
} else if(reading >= lowerthreshold) { // once the applied force sinks below the lower threshold...
if(press)
midimsg(128,note,0);
press = false; // the sensor is no longer in 'pressed' mode
}
return press;
}
[/code]