#include “Ultrasonic.h”
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
Ultrasonic ultrasonic(8, 7);
int midiMapped = 0;
int lastmidiMapped = 0;
void setup()
{
Serial.begin(115200);
}
void loop()
{
float x = ultrasonic.read(CM);
delay (50);
midiMapped = map(constrain(x, 5, 35), 5, 35, 48, 60);
if (lastmidiMapped != midiMapped) {
MIDI.sendNoteOff(lastmidiMapped, 0, 1);
MIDI.sendNoteOn(midiMapped, 127, 1);
lastmidiMapped = midiMapped;
delay(50);
}
}