exemple de code :
#include <midi_serialization.h>
#include <usbmidi.h>
#include <Bounce2.h>
// See midictrl.png in the example folder for the wiring diagram,
// as well as README.md.
int sensorValue;
int inter;
// variable to calibrate low value
int sensorLow = 60;
// variable to calibrate high value
int sensorHigh = 700;
const int interPin = 2;
void sendCC(uint8_t channel, uint8_t control, uint8_t value) {
USBMIDI.write(0xB0 | (channel & 0xf));
USBMIDI.write(control & 0x7f);
USBMIDI.write(value & 0x7f);
}
void sendNote(uint8_t channel, uint8_t note, uint8_t velocity) {
USBMIDI.write((velocity != 0 ? 0x90 : 0x80) | (channel & 0xf));
USBMIDI.write(note & 0x7f);
USBMIDI.write(velocity & 0x7f);
}
void setup() {
//touch.attach( touchPin, INPUT);
//touch.interval(5);
//Serial.begin(9600);
pinMode(interPin, INPUT_PULLUP);
}
void loop() {
//Handle USB communication
USBMIDI.poll();
while (USBMIDI.available()) {
// We must read entire available data, so in case we receive incoming
// MIDI data, the host wouldn't get stuck.
u8 b = USBMIDI.read();
}
inter = digitalRead(interPin);
if (inter == LOW) {
sensorValue = analogRead(A0);
Serial.println(sensorValue);
//Serial.println(sensorValue);
if (sensorValue > sensorLow && sensorValue < 150 ) {
sendNote(0, 64, 120);
delay(10);
}
else if (sensorValue > 150 && sensorValue < 300 ) {
sendNote(0, 66, 120);
delay(10);
}
else if (sensorValue > 300 && sensorValue < 600 ) {
sendNote(0, 68, 120);
delay(10);
}
else {
for ( int i = 50; i < 101; ++i) {
sendNote(0, i, 0);
delay(1);
}
}
}
else {
for ( int i = 50; i < 101; ++i) {
sendNote(0, i, 0);
delay(1);
}
}
// Flush the output.
USBMIDI.flush();
}
avec ce code si la valeur du capteur atteint 500, ça va déclencher les 3 notes (68, 66, et 64). puisque la valeur du capteur redescend une fois qu'elle a atteint son maximum.