checksensor function
This commit is contained in:
		@@ -113,56 +113,59 @@ void loop() {
 | 
				
			|||||||
    // Serial.println("loop");
 | 
					    // Serial.println("loop");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int state1 = sensor1.readRangeContinuousMillimeters();
 | 
					 | 
				
			||||||
    Serial.print("s1 : ");
 | 
					    Serial.print("s1 : ");
 | 
				
			||||||
    Serial.print(state1);
 | 
					    // int state1 = sensor1.readRangeContinuousMillimeters();
 | 
				
			||||||
    if ((state1 == 0 || state1 > 50) && tracksUp[0] == 0)
 | 
					    // Serial.print(state1);
 | 
				
			||||||
    {
 | 
					    // if ((state1 == 0 || state1 > 50) && tracksUp[0] == 0)
 | 
				
			||||||
      Serial.print(" ON");
 | 
					    // {
 | 
				
			||||||
      noteOn(0, 84, intensity);
 | 
					    //   Serial.print(" ON");
 | 
				
			||||||
      MidiUSB.flush();
 | 
					    //   noteOn(0, 84, intensity);
 | 
				
			||||||
      tracksUp[0] = 1;
 | 
					    //   MidiUSB.flush();
 | 
				
			||||||
    }else{
 | 
					    //   tracksUp[0] = 1;
 | 
				
			||||||
      Serial.print(" OFF");
 | 
					    // }else{
 | 
				
			||||||
      noteOff(0, 84, 0);
 | 
					    //   Serial.print(" OFF");
 | 
				
			||||||
      MidiUSB.flush();
 | 
					    //   noteOff(0, 84, 0);
 | 
				
			||||||
      tracksUp[0] = 0;
 | 
					    //   MidiUSB.flush();
 | 
				
			||||||
    }
 | 
					    //   tracksUp[0] = 0;
 | 
				
			||||||
 | 
					    // }
 | 
				
			||||||
 | 
					    checkSensor(sensor1, 0, 84);
 | 
				
			||||||
    Serial.print(" | ");
 | 
					    Serial.print(" | ");
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    int state2 = sensor2.readRangeContinuousMillimeters();
 | 
					 | 
				
			||||||
    Serial.print("s2 : ");
 | 
					    Serial.print("s2 : ");
 | 
				
			||||||
    Serial.print(state2);
 | 
					    // int state2 = sensor2.readRangeContinuousMillimeters();
 | 
				
			||||||
    if ((state2 == 0 || state2 > 50) && tracksUp[1] == 0){
 | 
					    // Serial.print(state2);
 | 
				
			||||||
      Serial.print(" ON");
 | 
					    // if ((state2 == 0 || state2 > 50) && tracksUp[1] == 0){
 | 
				
			||||||
      noteOn(0, 86, intensity);
 | 
					    //   Serial.print(" ON");
 | 
				
			||||||
      MidiUSB.flush();
 | 
					    //   noteOn(0, 86, intensity);
 | 
				
			||||||
      tracksUp[1] = 1;
 | 
					    //   MidiUSB.flush();
 | 
				
			||||||
    }else{
 | 
					    //   tracksUp[1] = 1;
 | 
				
			||||||
      Serial.print(" OFF");
 | 
					    // }else{
 | 
				
			||||||
      noteOff(0, 86, 0);
 | 
					    //   Serial.print(" OFF");
 | 
				
			||||||
      MidiUSB.flush();
 | 
					    //   noteOff(0, 86, 0);
 | 
				
			||||||
      tracksUp[1] = 0;
 | 
					    //   MidiUSB.flush();
 | 
				
			||||||
    }
 | 
					    //   tracksUp[1] = 0;
 | 
				
			||||||
 | 
					    // }
 | 
				
			||||||
 | 
					    checkSensor(sensor2, 1, 86);
 | 
				
			||||||
    Serial.print(" | ");
 | 
					    Serial.print(" | ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    int state3 = sensor3.readRangeContinuousMillimeters();
 | 
					 | 
				
			||||||
    Serial.print("s3 : ");
 | 
					    Serial.print("s3 : ");
 | 
				
			||||||
    Serial.print(state3);
 | 
					    // int state3 = sensor3.readRangeContinuousMillimeters();
 | 
				
			||||||
    // Serial.print(" | ");
 | 
					    // Serial.print(state3);
 | 
				
			||||||
    if ((state3 == 0 || state3 > 50) && tracksUp[2] == 0){
 | 
					    // // Serial.print(" | ");
 | 
				
			||||||
      Serial.print(" ON");
 | 
					    // if ((state3 == 0 || state3 > 50) && tracksUp[2] == 0){
 | 
				
			||||||
      noteOn(0, 88, intensity);
 | 
					    //   Serial.print(" ON");
 | 
				
			||||||
      MidiUSB.flush();
 | 
					    //   noteOn(0, 88, intensity);
 | 
				
			||||||
      tracksUp[2] = 1;
 | 
					    //   MidiUSB.flush();
 | 
				
			||||||
    }else{
 | 
					    //   tracksUp[2] = 1;
 | 
				
			||||||
      Serial.print(" OFF");
 | 
					    // }else{
 | 
				
			||||||
      noteOff(0, 88, 0);
 | 
					    //   Serial.print(" OFF");
 | 
				
			||||||
      MidiUSB.flush();
 | 
					    //   noteOff(0, 88, 0);
 | 
				
			||||||
      tracksUp[2] = 0;
 | 
					    //   MidiUSB.flush();
 | 
				
			||||||
    }
 | 
					    //   tracksUp[2] = 0;
 | 
				
			||||||
 | 
					    // }
 | 
				
			||||||
 | 
					    checkSensor(sensor3, 2, 88);
 | 
				
			||||||
    Serial.println("");
 | 
					    Serial.println("");
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  // if (sensor1.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
 | 
					  // 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) {
 | 
					void noteOn(byte channel, byte pitch, byte velocity) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
 | 
					  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user