movehub-async
Version:
Asynchronous methods for the Lego Boost Move Hub package
77 lines (59 loc) • 2.06 kB
JavaScript
const boost = require('./index');
(async () => {
// await boost.bleReadyAsync();
// const connectDetails = await boost.hubFoundAsync();
// const hub = await boost.connectAsync(connectDetails);
const hub = await boost.getHubAsync();
hub.on('error', err => {
console.log('error', err);
});
hub.on('disconnect', () => {
console.log('disconnect');
});
hub.on('distance', distance => {
console.log('distance', distance);
});
// hub.on('rssi', rssi => {
// console.log('rssi', rssi);
// });
// hub.on('port', portObject => {
// console.log('port', JSON.stringify(portObject, null, 1));
// });
// hub.on('color', color => {
// console.log('color', color);
// });
// hub.on('tilt', tilt => {
// console.log('tilt', JSON.stringify(tilt, null, 1));
// });
// hub.on('rotation', rotation => {
// console.log('rotation', JSON.stringify(rotation, null, 1));
// });
// Insert commands here
// await hub.ledAsync('red');
// await hub.ledAsync('yellow');
// await hub.ledAsync('green');
// await hub.drive(20, true);
// await hub.motorAngleMultiAsync(1000, 50, 50, true);
// Drive 2 meters forward
// await hub.drive(50, true);
// // After 2 meter drive, turn 90 degrees to the right
// await hub.turn(90, true);
// // Drive 1 meter backwards
// await hub.drive(-25, true);
// // Turn 180 degrees to the left
// await hub.turn(-180, true);
// Drive until reach a blocking object
await hub.driveUntil();
// Turn to the right until no blockig objects
await hub.turnUntil();
// // Turn 60 degrees back
// await hub.turn(-60, true);
// // Turn to the left until no blocking objects
// await hub.turnUntil(0);
// Turn 180 degrees
// await hub.motorAngleAsync('A', 980, 100, true);
// await hub.motorTimeMultiAsync(2, 100, 100, true);
// // Turn 180 degrees
// await hub.motorAngleAsync('B', 980, 100, true);
// await hub.ledAsync('red');
})();