Lab_interaccio/2016/hybridPlay1.0.1/IR.ino

26 lines
523 B
Arduino
Raw Permalink Normal View History

2025-02-25 21:29:42 +01:00
void updateIR(){
// Request and read the 2 address bytes from the GP2Y0E02B
Wire.beginTransmission(IR_ADDRESS);
Wire.write(IR_DISTANCE_REG);
Wire.endTransmission();
Wire.requestFrom(IR_ADDRESS, 2);
if (2 <= Wire.available()){
ir_high = Wire.read();
ir_low = Wire.read();
ir_distance = (ir_high * 16 + ir_low)/16/(int)pow(2,ir_shift); // Calculate the range in CM
}
if(ir_distance < 100 && ir_distance > 3){
valIR = int(ir_distance);
}else{
valIR = int(0);
}
}