Touchsensors + usbMIDI

Status
Not open for further replies.

Indisch

Member
Hi,
I'm working on a project with the Teensy 3.2. I want to build a Midi controller with touchsensors using the internal touchpins and usbMidi. But I have two questions/problems.

I have started writing a code (see below) but have the problem that the note keeps on playing repeatedly when I keep my finger on the sensor. How do I make it play only once and in the rhythm I tap the sensor. My second question is, how would I implement variable velocity. So it reacts to the way I play (how hard/fast I touch the sensor). I thought of using the threshold for that, but I guess thats not the right way.


const int channel = 1;
void setup() {
Serial.begin(9600);
}

void loop() {

if (touchRead(1) > 1000) {
usbMIDI.sendNoteOn (40, 99, channel);
}
if (touchRead(1) < 1000) {
usbMIDI.sendNoteOff (40, 0, channel);
}

Serial.println(touchRead(1));
while (usbMIDI.read()){}
delay(5);
}

Appreciate any help or advice :)
 

Attachments

  • TESTS.ino
    345 bytes · Views: 194
Last edited:
You need to add a variable to remember if you've already sent note-on. When it's not, do the first part where you check if it should turn on. When it is on, do the second part where to check if it should turn off. The idea is you do not want to be checking if the note should turn on when it's already on.

Kinda like this:

Code:
const int channel = 1;
bool noteIsOn = false;

void setup() {
  Serial.begin(9600);
}

void loop() {

  if (noteIsOn == false) {
    if (touchRead(1) > 1100) {
      usbMIDI.sendNoteOn (40, 99, channel);
      noteIsOn = true;
    }
  } else {
    if (touchRead(1) < 900) {
      usbMIDI.sendNoteOff (40, 0, channel);
      noteIsOn = false;
    }
  }
  Serial.println(touchRead(1));
  while (usbMIDI.read()) {}
  delay(5);
}

It also helps to use 2 different thresholds, where the on threshold is slightly higher. That way the note won't rapidly turn on & off if the signal is right at the threshold and has a small amount of noise. In this code, I changed 1000 to 1100 and 900. You might wish to adjust as you like.
 
Thanks for your quick repsonse. Thats a simple adjustment which makes a lot of sense. I guess the part with the variable velocity is a "bit" more complicated?
 
Hi again,
wanted to ask if someone could tell which MIDI message to use to send "Start/Pause", "Stop" and "Record", when a certrain Button is pressed. So I can record using a DAW without having to hit record on the computer.

Thanks for any help...
 
Thanks for the response. I'm still a bit confused how to implement it as a code. As an example, if I want to send "Play" with a button on Pin 1 which is set up with a Pull-Up resistor:

if (digitalRead(1) == LOW) //Button pressed
{
usbMIDI.sendSysEx(length, array); //length = 1538 for "Play", array = ???
}

Would length be 1538 (in hexadecimal 06 02: 06 for sub-ID 1 and 02 for sub-ID 2)? What would the array be?

As a DAW I use Logic 7, don't know if I can do it using the CC.
 
Status
Not open for further replies.
Back
Top