Hi, I'm currently doing a project where I need to make a distance sensor send a MIDI note so that it can trigger a piece of video on Resolume. I'm currently using the code below so that I can read the values from the sensor and that's all working fine and I've set it so that only at 6cm will it detect anything as I need it to be quite precise. I'm not sure how to now how to make it translate this into a MIDI note. I'm still a beginner and working through all the initial project examples but I need to get this finished soon so any help would be massively appreciated. Thank you
#define echoPin 11
#define trigPin 12
#define LEDPin 13
int maximumRange = 7;
int minimumRange = 5;
long duration, distance;
void setup() {
Serial.begin(9600); //starts the serial communication via USB
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT); //board LED for testing
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
// error handling
if (distance >= maximumRange || distance <= minimumRange) {
Serial.println("-1");
digitalWrite(LEDPin, HIGH);
} else {
Serial.println(distance);
digitalWrite(LEDPin, LOW);
}
delay(50);
}