Catégories
Liens
Ceci est une ancienne révision du document !
Contrôleur Midi DIY avec 12 touches. On utilise ici un module très simple à connecter à l'Arduino, le module MPR121 qui permet de
/* * Midi Controller with 12 capacitive sensors * Hardware : Arduino Leonardo (TeeOnArdu) + MPR121 * * See more : http://reso-nance.org/wiki/projet/c12/ */ #include <Wire.h> #include "Adafruit_MPR121.h" // Setup Adafruit_MPR121 cap = Adafruit_MPR121(); int touchCtl[] = {6,11,12,3,4,9,10,1,2,7,8,5}; // midi note in mapping const int channel = 1; // midi channel uint16_t lasttouched = 0; uint16_t currtouched = 0; elapsedMillis msec = 0; void setup() { if (!cap.begin(0x5A)) { while (1); } } void loop() { if (msec >= 20) { // sampling rate msec = 0; currtouched = cap.touched(); for (uint8_t i=0; i<12; i++) { // it if *is* touched and *wasnt* touched before, alert! if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) { usbMIDI.sendControlChange(touchCtl[i], 127, channel); } // if it *was* touched and now *isnt*, alert! if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) { usbMIDI.sendControlChange(touchCtl[i], 0, channel); } } // reset our state lasttouched = currtouched; } while (usbMIDI.read()) { // ignore incoming messages } }