pl3as3st0pm3
New member
Hello! This is my first arduino project. I decided to repeat the project of the touch midi controller on the Teensy 3.2 board, here is an example: https://www.youtube.com/watch?v=oSeH9Q4-yL8. I’ll be brief: it works, but not like in a video, where each press is processed as one, regardless of its duration, in my case, long touches sound like multiple short ones, as if I were pounding the sensor. The author of the project is not responding. Tell me what needs to be fixed in the code?
Thank you in advance!
Code:
unsigned int thresh = 3000;
unsigned int data;
int tickTime = 100;
byte readPins[] = {
0, 1, 3, 4, 23, 22, 19, 18
};
byte pitches[] = {
60, 62, 64, 65, 67, 69, 71, 72
};
byte playFlag[] = {
0, 0, 0, 0, 0, 0, 0, 0
};
byte tick[] = {
0, 0, 0, 0, 0, 0, 0, 0
};
void setup() {
usbMIDI.setHandleControlChange(OnControlChange);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
void loop() {
checkTouch();
checkTick();
usbMIDI.read();
}
void checkTouch() {
for(int i = 0; i < 8; i++) {
data = touchRead(readPins[i]);
if(data > thresh) {
usbMIDI.sendControlChange(1, constrain(map(data, thresh, 65535, 0, 127), 0, 127), 1);
if(playFlag[i] == 0) {
usbMIDI.sendNoteOn(pitches[i], 127, 1);
playFlag[i] = 1;
tick[i] = tickTime;
}
}
}
}
void checkTick() {
for(int i = 0; i < 8; i++) {
if(tick[i] == 0 && playFlag[i] == 1) {
playFlag[i] = 0;
usbMIDI.sendNoteOff(pitches[i], 0, 1);
}
if(tick[i] > 0) {
tick[i] = tick[i] - 1;
}
}
}
void OnControlChange(byte channel, byte controller, byte value) {
digitalWrite(13, HIGH);
thresh = value * 100;
delay(10);
digitalWrite(13, LOW);
}
Thank you in advance!