Hello,
For a theatre project I want to stick 5 flex sensors to a hand.
Each flex sensor sends midi data over usb.
This is the code that works perfectly to do this for 1 flex sensor (or also works with a LDR light sensor).
Now when I try this with more than 1 sensor I begin to have problems in my hairless MIDI output data.
I'm working on arduino uno and mac 10.12 and I use hairless MIDI for the conversion from serial to usb.
Then I use the MIDI data in ableton live.
I want that every sensor sends a specific range of MIDI notes.
Like the first sensor notes 0 - 15, 2nd sensor note 16 - 30 and so on.
I imagine that this is perfectly possible with the map function.
This is the code with one flex sensor:
byte noteON = 144;//note on command
int analogPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int analogVal = analogRead(analogPin);//read data
//we have to scale the lsr data to fit between 0 and 127 (this is the range of MIDI notes)
byte note = map(analogVal, 0, 900, 0, 127);//use the 0-900 range I measured
MIDImessage(noteON, note, 100);//turn note on
delay(300);//hold note for 300ms
MIDImessage(noteON, note, 0);//turn note off (note on with velocity 0)
delay(200);//wait 200ms until triggering next note
}
//send MIDI message
void MIDImessage(byte command, byte data1, byte data2) {
Serial.write(command);
Serial.write(data1);
Serial.write(data2);
}
This is my attempt for 2 sensors an LDR and a flex sensor, wich has not been working.
I get my data in hairless , which are more different MIDI notes. But when I use the MIDI notes that come into Ableton there is one note constantly playing the same tone.
byte noteON = 144;//note on command
int analogPin5 = A5;// LSR sensor
int analogPin1 = A1;// FLEX sensor
void setup() {
Serial.begin(9600);
}
void loop() {
int analogVal5 = analogRead(analogPin5);//read data
int analogVal1 = analogRead(analogPin1);
//we have to scale the lsr data to fit between 0 and 127 (this is the range of MIDI notes)
byte note5 = map(analogVal5, 0, 900, 0, 50);//use the 0-900 range I measured
byte note1 = map(analogVal1, 0, 900, 51, 127);
MIDImessage(noteON, note5, 100);//turn note on
delay(300);//hold note for 300ms
MIDImessage(noteON, note5, 0);//turn note off (note on with velocity 0)
delay(200);//wait 200ms until triggering next note
MIDImessage(noteON, note1, 100);//turn note on
delay(300);//hold note for 300ms
MIDImessage(noteON, note1, 0);//turn note off (note on with velocity 0)
delay(200);//wait 200ms until triggering next note
}
//send MIDI message
void MIDImessage(byte command, byte data1, byte data2) {
Serial.write(command);
Serial.write(data1);
Serial.write(data2);
}
Is it possible to use multiple sensors with this code in a usable way?
Or another way that I can make this project work?
It is necessary that the MIDI goes via usb, without a hardware MIDI port.
Thank you very much for any help!

