checksensor function

This commit is contained in:
Bachir Soussi Chiadmi 2024-06-26 15:26:23 +02:00
parent a9db88e9b6
commit a1267cfcca
1 changed files with 62 additions and 41 deletions

View File

@ -113,56 +113,59 @@ void loop() {
// Serial.println("loop");
int state1 = sensor1.readRangeContinuousMillimeters();
Serial.print("s1 : ");
Serial.print(state1);
if ((state1 == 0 || state1 > 50) && tracksUp[0] == 0)
{
Serial.print(" ON");
noteOn(0, 84, intensity);
MidiUSB.flush();
tracksUp[0] = 1;
}else{
Serial.print(" OFF");
noteOff(0, 84, 0);
MidiUSB.flush();
tracksUp[0] = 0;
}
// int state1 = sensor1.readRangeContinuousMillimeters();
// Serial.print(state1);
// if ((state1 == 0 || state1 > 50) && tracksUp[0] == 0)
// {
// Serial.print(" ON");
// noteOn(0, 84, intensity);
// MidiUSB.flush();
// tracksUp[0] = 1;
// }else{
// Serial.print(" OFF");
// noteOff(0, 84, 0);
// MidiUSB.flush();
// tracksUp[0] = 0;
// }
checkSensor(sensor1, 0, 84);
Serial.print(" | ");
int state2 = sensor2.readRangeContinuousMillimeters();
Serial.print("s2 : ");
Serial.print(state2);
if ((state2 == 0 || state2 > 50) && tracksUp[1] == 0){
Serial.print(" ON");
noteOn(0, 86, intensity);
MidiUSB.flush();
tracksUp[1] = 1;
}else{
Serial.print(" OFF");
noteOff(0, 86, 0);
MidiUSB.flush();
tracksUp[1] = 0;
}
// int state2 = sensor2.readRangeContinuousMillimeters();
// Serial.print(state2);
// if ((state2 == 0 || state2 > 50) && tracksUp[1] == 0){
// Serial.print(" ON");
// noteOn(0, 86, intensity);
// MidiUSB.flush();
// tracksUp[1] = 1;
// }else{
// Serial.print(" OFF");
// noteOff(0, 86, 0);
// MidiUSB.flush();
// tracksUp[1] = 0;
// }
checkSensor(sensor2, 1, 86);
Serial.print(" | ");
int state3 = sensor3.readRangeContinuousMillimeters();
Serial.print("s3 : ");
Serial.print(state3);
// Serial.print(" | ");
if ((state3 == 0 || state3 > 50) && tracksUp[2] == 0){
Serial.print(" ON");
noteOn(0, 88, intensity);
MidiUSB.flush();
tracksUp[2] = 1;
}else{
Serial.print(" OFF");
noteOff(0, 88, 0);
MidiUSB.flush();
tracksUp[2] = 0;
}
// int state3 = sensor3.readRangeContinuousMillimeters();
// Serial.print(state3);
// // Serial.print(" | ");
// if ((state3 == 0 || state3 > 50) && tracksUp[2] == 0){
// Serial.print(" ON");
// noteOn(0, 88, intensity);
// MidiUSB.flush();
// tracksUp[2] = 1;
// }else{
// Serial.print(" OFF");
// noteOff(0, 88, 0);
// MidiUSB.flush();
// tracksUp[2] = 0;
// }
checkSensor(sensor3, 2, 88);
Serial.println("");
// if (sensor1.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
@ -172,6 +175,24 @@ void loop() {
}
void checkSensor(VL53L0X sensor, int index, int note){
int state = sensor.readRangeContinuousMillimeters();
// Serial.print("s3 : ");
Serial.print(state);
// Serial.print(" | ");
if ((state == 0 || state > 50) && tracksUp[index] == 0){
Serial.print(" ON");
noteOn(0, note, intensity);
MidiUSB.flush();
tracksUp[index] = 1;
}else{
Serial.print(" OFF");
noteOff(0, note, 0);
MidiUSB.flush();
tracksUp[index] = 0;
}
}
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};