Skip to content

Instantly share code, notes, and snippets.

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

What would you like to do?
function getDistance(port,addr){
return new Promise(function(resolve,reject){
const slave = yield;
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;
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.