Skip to content

Instantly share code, notes, and snippets.

@naokisekiguchi naokisekiguchi/distance.js
Last active Nov 10, 2016

Embed
What would you like to do?
CHIRIMENで距離センサ(SRF02)を取得する
function getDistance(port,addr){
return new Promise(function(resolve,reject){
spawn(function(){
const slave = yield port.open(addr);
yield slave.write8(0x00, 0x00);
yield sleep(1);
slave.write8(0x00, 0x51);
yield sleep(70);
const highBit = yield slave.read8(0x02, true);
const lowBit = yield slave.read8(0x03, true);
const distance = (highBit << 8) + lowBit;
resolve(distance);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.