Teensy 3.2, USB Midi send NoteOn / Off

Status
Not open for further replies.

teensy_ino

Active member
Hello everybody,

I am trying to send Midi NoteOn / Off with the Teensy 3.2 depending on the voltage applied to A1 via USB.
Note On, for example, only when the voltage is above 3V, NoteOff only when the voltage is below 1V.

Basically it works - but:
NoteOn and Off messages are output as a continuous signal ...
That sounds like an old alternating current bell in the connected midi instrument ... - and because of the high midi traffic it leads to the midi
instrument "hanging up" ...

Code:
float voltage = 0;
float voltage_Old = 0;

int midiNeu = 0 ;
int midiOLD = 0 ;

void setup() {
  analogReadResolution (16); // 16 Bit = 65536 (3.31 / 65536);
  Serial.begin(115200);
}

void loop() {

  voltage = analogRead(A1) * (3.31 / 65536);


  if (voltage > 3.00 ) {
    usbMIDI.sendNoteOn(40, 127, 1);
    voltage_Old = voltage;
    //midiOLD = midiNeu ;
  }
  if (voltage < 1.00 ) {
    usbMIDI.sendNoteOff(40, 0, 1);
    voltage_Old = voltage;
    //midiOLD = midiNeu ;
  }

  //delay(250);
  { Serial.print("voltage = ");
    Serial.print(voltage);
    Serial.print("\t");

    Serial.print("voltage_Old = ");
    Serial.print(voltage_Old);
    Serial.print("\t");

    Serial.print("midiOLD = ");
    Serial.print(midiOLD);
    Serial.print("\t");

    Serial.print("midiNeu = ");
    Serial.println(midiNeu);


  }
  while (usbMIDI.read()) {  // Eingehende Nachrichten lesen und ignorieren !
  }
}

How can I achieve that Note ON / Off is only output once when the threshold values are reached?

regards
 
You do what you ask for, compare the voltage with the previous voltage, needs a varible to save this, and send midi when threshhold is crossed.
 
You do what you ask for, compare the voltage with the previous voltage, needs a varible to save this, and send midi when threshhold is crossed.

Hi mlu,

Thank you for your information.


The comparison of the voltages and the saving in the variables basically works so far - but the midi notes are unfortunately triggered permanently.
My goal is to output only 1 x NoteOn or NoteOff when the threshold values are reached.

So far I haven't been able to find a solution.

What does the code have to look like?


regards
 
Try the following:

Code:
float voltage = 0;
float voltage_Old = 0;

int midiNeu = 0 ;
int midiOLD = 0 ;

void setup() {
  analogReadResolution (16); // 16 Bit = 65536 (3.31 / 65536);
  Serial.begin(115200);
}

void loop() {

  voltage = analogRead(A1) * (3.31 / 65536);


  if ((voltage > 3.00 ) && (voltage_Old <= 3.00 ){
    usbMIDI.sendNoteOn(40, 127, 1);
    voltage_Old = voltage;
    //midiOLD = midiNeu ;
  }
  if ((voltage < 1.00 ) && (voltage_Old >= 1.00 ) {
    usbMIDI.sendNoteOff(40, 0, 1);
    voltage_Old = voltage;
    //midiOLD = midiNeu ;
  }

  //delay(250);
  { Serial.print("voltage = ");
    Serial.print(voltage);
    Serial.print("\t");

    Serial.print("voltage_Old = ");
    Serial.print(voltage_Old);
    Serial.print("\t");

    Serial.print("midiOLD = ");
    Serial.print(midiOLD);
    Serial.print("\t");

    Serial.print("midiNeu = ");
    Serial.println(midiNeu);


  }
  while (usbMIDI.read()) {  // Eingehende Nachrichten lesen und ignorieren !
  }
}
 
Status
Not open for further replies.
Back
Top