Hi!
I am trying to build a midi controller with a hex layout for playing microtonal scales and stuff.
I have a code which incorporates 3x Mpr121, so i get a total of 36 notes, which is fine. My plan is to use 2 Fsr ( i will build them out of Velostat and Coppertape) to get velocity and aftertouch.
Under the rows of buttons i plan to put a piece of foam, and beneath that the 2 fsr will be placed.
I am using PieterP´s Control Surface library.
I tried to write the arduino code for myself, but i just cant accomplish to incorporate velocity or aftertouch.
(CC´s or Pitchbend is no problem)
Right now the code sends fixed Note On´s with 127 and Note Off´s with 0, so i guess i would have to
change that to a variable and get the value from the Fsr?
here is my code (i also think that could be written way more elegant, but it works for me)
#include <Control_Surface.h>
#include <Adafruit_MPR121.h>
#include <Wire.h>
USBMIDI_Interface midi;
#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif
Adafruit_MPR121 cap1 = Adafruit_MPR121();
Adafruit_MPR121 cap2 = Adafruit_MPR121();
Adafruit_MPR121 cap3 = Adafruit_MPR121();
// Keeps track of the last pins touched
// so we know when buttons are 'released'
uint16_t lasttouched = 0;
uint16_t currtouched = 0;
uint16_t lasttouched2 = 0;
uint16_t currtouched2 = 0;
uint16_t lasttouched3 = 0;
uint16_t currtouched3 = 0;
void setup() {
if (!cap1.begin(0x5A));
if (!cap2.begin(0x5B));
if (!cap3.begin(0x5C));
Control_Surface.begin();
}
void loop() {
currtouched = cap1.touched();
currtouched2 = cap2.touched();
currtouched3 = cap3.touched();
if ((currtouched & _BV(0)) && !(lasttouched & _BV(0)) ) {
midi.sendNoteOn(42, 127);
}
if (!(currtouched & _BV(0)) && (lasttouched & _BV(0)) ) {
midi.sendNoteOff(42, 0);
}
if ((currtouched & _BV(1)) && !(lasttouched & _BV(1)) ) {
midi.sendNoteOn(43, 127);
}
if (!(currtouched & _BV(1)) && (lasttouched & _BV(1)) ) {
midi.sendNoteOff(43, 0);
}
if ((currtouched & _BV(2)) && !(lasttouched & _BV(2)) ) {
midi.sendNoteOn(44, 127);
}
if (!(currtouched & _BV(2)) && (lasttouched & _BV(2)) ) {
midi.sendNoteOff(44, 0);
}
if ((currtouched & _BV(3)) && !(lasttouched & _BV(3)) ) {
midi.sendNoteOn(45, 127);
}
if (!(currtouched & _BV(3)) && (lasttouched & _BV(3)) ) {
midi.sendNoteOff(45, 0);
}
if ((currtouched & _BV(4)) && !(lasttouched & _BV(4)) ) {
midi.sendNoteOn(46, 127);
}
if (!(currtouched & _BV(4)) && (lasttouched & _BV(4)) ) {
midi.sendNoteOff(46, 0);
}
if ((currtouched & _BV(5)) && !(lasttouched & _BV(5)) ) {
midi.sendNoteOn(47, 127);
}
if (!(currtouched & _BV(5)) && (lasttouched & _BV(5)) ) {
midi.sendNoteOff(47, 0);
}
if ((currtouched & _BV(6)) && !(lasttouched & _BV(6)) ) {
midi.sendNoteOn(48, 127);
}
if (!(currtouched & _BV(6)) && (lasttouched & _BV(6)) ) {
midi.sendNoteOff(48, 0);
}
if ((currtouched & _BV(7)) && !(lasttouched & _BV(7)) ) {
midi.sendNoteOn(49, 127);
}
if (!(currtouched & _BV(7)) && (lasttouched & _BV(7)) ) {
midi.sendNoteOff(49, 0);
}
if ((currtouched & _BV(8)) && !(lasttouched & _BV(8)) ) {
midi.sendNoteOn(50, 127);
}
if (!(currtouched & _BV(8)) && (lasttouched & _BV(8)) ) {
midi.sendNoteOff(50, 0);
}
if ((currtouched & _BV(9)) && !(lasttouched & _BV(9)) ) {
midi.sendNoteOn(51, 127);
}
if (!(currtouched & _BV(9)) && (lasttouched & _BV(9)) ) {
midi.sendNoteOff(51, 0);
}
if ((currtouched & _BV(10)) && !(lasttouched & _BV(10)) ) {
midi.sendNoteOn(52, 127);
}
if (!(currtouched & _BV(10)) && (lasttouched & _BV(10)) ) {
midi.sendNoteOff(52, 0);
}
if ((currtouched & _BV(11)) && !(lasttouched & _BV(11)) ) {
midi.sendNoteOn(53, 127);
}
if (!(currtouched & _BV(11)) && (lasttouched & _BV(11)) ) {
midi.sendNoteOff(53, 0);
}
if ((currtouched2 & _BV(0)) && !(lasttouched2 & _BV(0)) ) {
midi.sendNoteOn(54, 127);
}
if (!(currtouched2 & _BV(0)) && (lasttouched2 & _BV(0)) ) {
midi.sendNoteOff(54, 0);
}
if ((currtouched2 & _BV(1)) && !(lasttouched2 & _BV(1)) ) {
midi.sendNoteOn(55, 127);
}
if (!(currtouched2 & _BV(1)) && (lasttouched2 & _BV(1)) ) {
midi.sendNoteOff(55, 0);
}
if ((currtouched2 & _BV(2)) && !(lasttouched2 & _BV(2)) ) {
midi.sendNoteOn(56, 127);
}
if (!(currtouched2 & _BV(2)) && (lasttouched2 & _BV(2)) ) {
midi.sendNoteOff(56, 0);
}
if ((currtouched2 & _BV(3)) && !(lasttouched2 & _BV(3)) ) {
midi.sendNoteOn(57, 127);
}
if (!(currtouched2 & _BV(3)) && (lasttouched2 & _BV(3)) ) {
midi.sendNoteOff(57, 0);
}
if ((currtouched2 & _BV(4)) && !(lasttouched2 & _BV(4)) ) {
midi.sendNoteOn(58, 127);
}
if (!(currtouched2 & _BV(4)) && (lasttouched2 & _BV(4)) ) {
midi.sendNoteOff(58, 0);
}
if ((currtouched2 & _BV(5)) && !(lasttouched2 & _BV(5)) ) {
midi.sendNoteOn(59, 127);
}
if (!(currtouched2 & _BV(5)) && (lasttouched2 & _BV(5)) ) {
midi.sendNoteOff(59, 0);
}
if ((currtouched2 & _BV(6)) && !(lasttouched2 & _BV(6)) ) {
midi.sendNoteOn(60, 127);
}
if (!(currtouched2 & _BV(6)) && (lasttouched2 & _BV(6)) ) {
midi.sendNoteOff(60, 0);
}
if ((currtouched2 & _BV(7)) && !(lasttouched2 & _BV(7)) ) {
midi.sendNoteOn(61, 127);
}
if (!(currtouched2 & _BV(7)) && (lasttouched2 & _BV(7)) ) {
midi.sendNoteOff(61, 0);
}
if ((currtouched2 & _BV(8)) && !(lasttouched2 & _BV(8)) ) {
midi.sendNoteOn(62, 127);
}
if (!(currtouched2 & _BV(8)) && (lasttouched2 & _BV(8)) ) {
midi.sendNoteOff(62, 0);
}
if ((currtouched2 & _BV(9)) && !(lasttouched2 & _BV(9)) ) {
midi.sendNoteOn(63, 127);
}
if (!(currtouched2 & _BV(9)) && (lasttouched2 & _BV(9)) ) {
midi.sendNoteOff(63, 0);
}
if ((currtouched2 & _BV(10)) && !(lasttouched2 & _BV(10)) ) {
midi.sendNoteOn(64, 127);
}
if (!(currtouched2 & _BV(10)) && (lasttouched2 & _BV(10)) ) {
midi.sendNoteOff(64, 0);
}
if ((currtouched2 & _BV(11)) && !(lasttouched2 & _BV(11)) ) {
midi.sendNoteOn(65, 127);
}
if (!(currtouched2 & _BV(11)) && (lasttouched2 & _BV(11)) ) {
midi.sendNoteOff(65, 0);
}
if ((currtouched3 & _BV(0)) && !(lasttouched3 & _BV(0)) ) {
midi.sendNoteOn(66, 127);
}
if (!(currtouched3 & _BV(0)) && (lasttouched3 & _BV(0)) ) {
midi.sendNoteOff(66, 0);
}
if ((currtouched3 & _BV(1)) && !(lasttouched3 & _BV(1)) ) {
midi.sendNoteOn(67, 127);
}
if (!(currtouched3 & _BV(1)) && (lasttouched3 & _BV(1)) ) {
midi.sendNoteOff(67, 0);
}
if ((currtouched3 & _BV(2)) && !(lasttouched3 & _BV(2)) ) {
midi.sendNoteOn(68, 127);
}
if (!(currtouched3 & _BV(2)) && (lasttouched3 & _BV(2)) ) {
midi.sendNoteOff(68, 0);
}
if ((currtouched3 & _BV(3)) && !(lasttouched3 & _BV(3)) ) {
midi.sendNoteOn(69, 127);
}
if (!(currtouched3 & _BV(3)) && (lasttouched3 & _BV(3)) ) {
midi.sendNoteOff(69, 0);
}
if ((currtouched3 & _BV(4)) && !(lasttouched3 & _BV(4)) ) {
midi.sendNoteOn(70, 127);
}
if (!(currtouched3 & _BV(4)) && (lasttouched3 & _BV(4)) ) {
midi.sendNoteOff(70, 0);
}
if ((currtouched3 & _BV(5)) && !(lasttouched3 & _BV(5)) ) {
midi.sendNoteOn(71, 127);
}
if (!(currtouched3 & _BV(5)) && (lasttouched3 & _BV(5)) ) {
midi.sendNoteOff(71, 0);
}
if ((currtouched3 & _BV(6)) && !(lasttouched3 & _BV(6)) ) {
midi.sendNoteOn(72, 127);
}
if (!(currtouched3 & _BV(6)) && (lasttouched3 & _BV(6)) ) {
midi.sendNoteOff(72, 0);
}
if ((currtouched3 & _BV(7)) && !(lasttouched3 & _BV(7)) ) {
midi.sendNoteOn(73, 127);
}
if (!(currtouched3 & _BV(7)) && (lasttouched3 & _BV(7)) ) {
midi.sendNoteOff(73, 0);
}
if ((currtouched3 & _BV(8)) && !(lasttouched3 & _BV(8)) ) {
midi.sendNoteOn(74, 127);
}
if (!(currtouched3 & _BV(8)) && (lasttouched3 & _BV(8)) ) {
midi.sendNoteOff(74, 0);
}
if ((currtouched3 & _BV(9)) && !(lasttouched3 & _BV(9)) ) {
midi.sendNoteOn(75, 127);
}
if (!(currtouched3 & _BV(9)) && (lasttouched3 & _BV(9)) ) {
midi.sendNoteOff(75, 0);
}
if ((currtouched3 & _BV(10)) && !(lasttouched3 & _BV(10)) ) {
midi.sendNoteOn(76, 127);
}
if (!(currtouched3 & _BV(10)) && (lasttouched3 & _BV(10)) ) {
midi.sendNoteOff(76, 0);
}
if ((currtouched3 & _BV(11)) && !(lasttouched3 & _BV(11)) ) {
midi.sendNoteOn(77, 127);
}
if (!(currtouched3 & _BV(11)) && (lasttouched3 & _BV(11)) ) {
midi.sendNoteOff(77, 0);
}
// reset our state
lasttouched = currtouched;
lasttouched2 = currtouched2;
lasttouched3 = currtouched3;
Control_Surface.loop();
}