Hi - I am using my teensy 3.1 to turn sensor data into MIDI which is sent to my computer over usb and used in MAX MSP. I would like have MAXMSP receive data that is positive in one direction in negative in the other. Ideally, I'd like to be able to use usbMIDI.sendControlChange() to send values -127 to 127, but this seems not possible. Any ideas for an alternative? usbMIDI.sendPitchBend() seems like it fits the description perfectly, but I can't seem to get it to output anything besides a 0 or 1.
here is more specificity if helpful
_________________________________
I am using a postion sensitive touchstrip
https://www.sparkfun.com/products/8680
That I would like to control the frequency of a sine wave in MAXMSP. it is easy enough to use the absolute position of the touchstrip to do this and just map the values of finger position to frequency. However, I would like to use the strip only for relative position. So when i press my finger down, there is no output. Just negative output as I travel down the strip, away from the start point. and Positive when I travel up. I finally got code working so that it outputs (over Serial) a postive, increasing number from 0 when i travel up from the startpoint, and a negative, decreasing number from 0 when i travel downwards (as well as the moment of contact and release). I would like to be able to do this in MIDI, because it is much easier to deal with in MAX MSP.
ANY IDEAS?
here is my code
#include <QueueArray.h>
boolean pressed = false;
int delayStart = 0;
int initValue = 0;
int currentValue=0;
int lastValue=10;
int s = 0;
QueueArray <int> history;
void setup(){
Serial.begin(57600);
pinMode(A0,INPUT);
history.setPrinter (Serial);
}
void loop(){
s = (analogRead(A0)/8);
if (!pressed){
if(s>2){
if(delayStart==0){
delayStart = millis();
//usbMIDI.sendNoteOn(1,127,1);
Serial.println("CONTACT");
}
if ((millis()-delayStart)>30){
pressed = true;
initValue = s;
lastValue = initValue;
delayStart = 0;
for(int i = 0; i < 700; i++) { //100 values is actually only 100*20microseconds =2ms lets give it like 5ms thats not too much lag. so 250 in queue?
history.enqueue(initValue);
}
//usbMIDI.sendNoteOn(2,127,1);
Serial.println("PRESSED");
}
} else {
if (delayStart==!0){
Serial.println("bad zero");
}
//delayStart = 0; //so this is whats causing the double CONTACT hiccup. the sensor sometimes drops down then back up again very quickly when pressed. i want to totally ignore this - but commenting it out makes values fucked. why?
}
} else{
currentValue = history.dequeue();
history.enqueue(s);
if(abs(currentValue-lastValue)>1){ //only output changes - ??what if you press down at beggingin at 10. then you wont output until you move?
int outty = (currentValue-initValue);
usbMIDI.sendControlChange(20,outty,1);
/*if(outty>=0){
usbMIDI.sendControlChange(13,outty,1);
}
if(outty<0){
outty = (outty*-1);
usbMIDI.sendControlChange(14,outty,1);
}
*/
lastValue=currentValue;
}
if (s<2){ //*** maybe i should also have some sort of protection against very very short jumps to zero. like anything less than 10ms i discard
//***i want to put a millis() on every line but is that too fast. should i be using something besides arduino serial monitor for th
pressed=false;
while(history.count() > 0) {
history.dequeue(); //clear queue
}
//usbMIDI.sendNoteOn(3,127,1);
Serial.println("RELEASED");
}
}
}
here is more specificity if helpful
_________________________________
I am using a postion sensitive touchstrip
https://www.sparkfun.com/products/8680
That I would like to control the frequency of a sine wave in MAXMSP. it is easy enough to use the absolute position of the touchstrip to do this and just map the values of finger position to frequency. However, I would like to use the strip only for relative position. So when i press my finger down, there is no output. Just negative output as I travel down the strip, away from the start point. and Positive when I travel up. I finally got code working so that it outputs (over Serial) a postive, increasing number from 0 when i travel up from the startpoint, and a negative, decreasing number from 0 when i travel downwards (as well as the moment of contact and release). I would like to be able to do this in MIDI, because it is much easier to deal with in MAX MSP.
ANY IDEAS?
here is my code
#include <QueueArray.h>
boolean pressed = false;
int delayStart = 0;
int initValue = 0;
int currentValue=0;
int lastValue=10;
int s = 0;
QueueArray <int> history;
void setup(){
Serial.begin(57600);
pinMode(A0,INPUT);
history.setPrinter (Serial);
}
void loop(){
s = (analogRead(A0)/8);
if (!pressed){
if(s>2){
if(delayStart==0){
delayStart = millis();
//usbMIDI.sendNoteOn(1,127,1);
Serial.println("CONTACT");
}
if ((millis()-delayStart)>30){
pressed = true;
initValue = s;
lastValue = initValue;
delayStart = 0;
for(int i = 0; i < 700; i++) { //100 values is actually only 100*20microseconds =2ms lets give it like 5ms thats not too much lag. so 250 in queue?
history.enqueue(initValue);
}
//usbMIDI.sendNoteOn(2,127,1);
Serial.println("PRESSED");
}
} else {
if (delayStart==!0){
Serial.println("bad zero");
}
//delayStart = 0; //so this is whats causing the double CONTACT hiccup. the sensor sometimes drops down then back up again very quickly when pressed. i want to totally ignore this - but commenting it out makes values fucked. why?
}
} else{
currentValue = history.dequeue();
history.enqueue(s);
if(abs(currentValue-lastValue)>1){ //only output changes - ??what if you press down at beggingin at 10. then you wont output until you move?
int outty = (currentValue-initValue);
usbMIDI.sendControlChange(20,outty,1);
/*if(outty>=0){
usbMIDI.sendControlChange(13,outty,1);
}
if(outty<0){
outty = (outty*-1);
usbMIDI.sendControlChange(14,outty,1);
}
*/
lastValue=currentValue;
}
if (s<2){ //*** maybe i should also have some sort of protection against very very short jumps to zero. like anything less than 10ms i discard
//***i want to put a millis() on every line but is that too fast. should i be using something besides arduino serial monitor for th
pressed=false;
while(history.count() > 0) {
history.dequeue(); //clear queue
}
//usbMIDI.sendNoteOn(3,127,1);
Serial.println("RELEASED");
}
}
}