Lors que je téléverse le code, tout fonctionne bien, mais lorsque je déconnecte le usb de mon arduino Leonardo, alors il ne se passe plus rien.
Je dois retéléversé mon code pour que tout fonctionne à nouveau.
Merci beaucoup
#include <Wire.h>
#include "Adafruit_MPR121.h"
#include "MIDIUSB.h"
#define _BV(bit) (1 << (bit))
Adafruit_MPR121 cap = Adafruit_MPR121();
int noteMidi[] = {60, 62, 64, 65, 67, 69, 71};
int noteClavier[] = {"c", "d", "e", "f", "g", "a", "b"};
int noteMaximum = 7;
uint16_t lasttouched = 0;
uint16_t currtouched = 0;
void setup() {
Serial.begin(115200);
while (!Serial) { // needed to keep leonardo/micro from starting too fast!
delay(10);
}
Serial.println("Adafruit MPR121 Capacitive Touch sensor test");
if (!cap.begin(0x5A)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}
Serial.println("MPR121 found!");
}
void loop() {
currtouched = cap.touched();
for (uint8_t i = 0; i < noteMaximum; i++) {
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
//Serial.print(i); Serial.println(" touched");
Serial.println("Sending note on");
noteOn( 10, noteMidi[i], 64); // Channel 0, middle C, normal velocity
MidiUSB.flush();
}
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
//Serial.print(i); Serial.println(" released");
Serial.println("Sending note off");
noteOff(10, noteMidi[i], 64); // Channel 0, middle C, normal velocity
MidiUSB.flush();
}
}
lasttouched = currtouched;
delay(100);
}
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
}