readUltrasonic method
Reads a value from the 'Ultrasonic Ranger' in the range form range 5-300cm. http://wiki.friendlyarm.com/wiki/index.php/BakeBit_-_Ultrasonic_Ranger
Implementation
int readUltrasonic(int pin) {
autoWait();
var error = I2Cexception.empty();
for (var i = 0; i < retry; ++i) {
try {
writeI2Cblock(HatCmd(ultraSonicCmd).getCmdSeqExt(pin));
sleep(Duration(milliseconds: 100));
var data = i2c.readBytesReg(hatArduinoI2Caddress, hatRegister, 3);
_updateLastAction();
return (data[1] & 0xff) * 256 | (data[2] & 0xff);
} on I2Cexception catch (e) {
error = e;
sleep(Duration(milliseconds: delay));
}
}
throw error;
}