Hello
Another problem comes up:(
Now, I have finally set up my sensors and when they are out of range, they return 100 (int).
I want to find the sensor which has detect an item closer from the other 6 sensors.
So the code is:
NewPing sB(TRIGGER_PIN_B, ECHO_PIN_B, distance);
NewPing sBL(TRIGGER_PIN_BL, ECHO_PIN_BL, distance);
NewPing sBR(TRIGGER_PIN_BR, ECHO_PIN_BR, distance);
NewPing sML(TRIGGER_PIN_ML, ECHO_PIN_ML, distance);
NewPing sMR(TRIGGER_PIN_MR, ECHO_PIN_MR, distance);
NewPing sL(TRIGGER_PIN_L, ECHO_PIN_L, distance);
NewPing sR(TRIGGER_PIN_R, ECHO_PIN_R, distance);
unsigned int SDB = sB.ping();
unsigned int SDBL = sBL.ping();
unsigned int SDBR = sBR.ping();
unsigned int SDML = sML.ping();
unsigned int SDMR = sMR.ping();
unsigned int SDL = sL.ping();
unsigned int SDR = sR.ping();
senB = SDB / US_ROUNDTRIP_CM;
senBL = SDBL / US_ROUNDTRIP_CM;
senBR = SDBR / US_ROUNDTRIP_CM;
senML = SDML / US_ROUNDTRIP_CM;
senMR = SDMR / US_ROUNDTRIP_CM;
senL = SDL / US_ROUNDTRIP_CM;
senR = SDR / US_ROUNDTRIP_CM;
int *convert[7] = {&senB, &senBL, &senBR, &senML, &senMR, &senL, &senR};
temp = 100;
for(int i = 0; i <= 6; i++) {
if(*(convert[i]) == 0) {
*convert[i] = temp;
}
}
int *sensor[7] = {&senB, &senBL, &senBR, &senML, &senMR, &senL, &senR};
temp1 = 100;
for(int i = 0; i <= 6; i++) {
if(*(sensor[i]) < temp1) {
temp1 = *(sensor[i]);
sensor = i;
}
}
}
Serial.println(sensor);
delay(1000);
instead of returning back the position of sensor in the array (0 - 6) it randomly returns numbers from '0' to '6'