26 lines
523 B
C++
26 lines
523 B
C++
|
|
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);
|
|
}
|
|
|
|
}
|