Package Exports
- movehub-async
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (movehub-async) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
movehub async
Simple to use asynchronous functions for the Lego Boost Move Hub
Install
$ npm install movehub-async
Usage
const boost = require('movehub-async');
const hub = await boost.getHubAsync();
await hub.ledAsync('red');
await hub.ledAsync('yellow');
await hub.ledAsync('green');
await hub.motorTimeMultiAsync(10, 20, 20);
await hub.motorAngleAsync('C', 600, 5);
It is also possible to wait that motor execution has stopped
await hub.ledAsync('red');
// Continue when led is red
await hub.motorTimeMultiAsync(10, 20, 20, true);
// Continue 10 sec later
await hub.motorTimeMultiAsync(5, 20, 20, true);
// Continue 5 sec later
await hub.motorAngleAsync('C', 800, 50, true);
// Continue some time later
await hub.ledAsync('green');
// Continue when led is green
API
Check complete non-async API definition from Lego Boost Move Hub. Asynchronous version of the method has an Async-suffix in the name, e.g. motorTimeMulti
-> motorTimeMultiAsync
.
- boost.getHubAsync()
Create a connection to the Hub. Internally calls bleReadyAsync
, hubFoundAsync
and connectAsync
.
const hub = await boost.getHubAsync();
- boost.bleReadyAsync()
Wait for BLE device to be ready.
await boost.bleReadyAsync();
- boost.hubFoundAsync()
Wait for MoveHub found event.
const connectDetails = await boost.hubFoundAsync();
- boost.connectAsync(connectDetails)
Initialize and wait for the connection to the Hub.
const hub = await boost.connectAsync(connectDetails);
- hub.ledAsync(color)
Control the LED on the Move Hub.
await hub.ledAsync('red');
- hub.motorTimeAsync(port, seconds, dutyCycle = 100, wait = false)
Run a motor for specific time. Await returns when command is sent to Hub.
await hub.motorTimeAsync('C', 5, 50);
// Continue almost immediately when command is sent to Hub
await hub.motorTimeAsync('C', 5, 50, true);
// Continue 5 seconds later
- hub.motorTimeMultiAsync(seconds, dutyCycleA = 100, dutyCycleB = 100, wait = false)
Run both motors (A and B) for specific time. Await returns when command is sent to Hub.
// Drive forward for 10 seconds
await hub.motorTimeMultiAsync(10, 20, 20, true);
// Continue 10 seconds later
- hub.motorAngleAsync(port, angle, dutyCycle = 100, wait = false)
Turn a motor by specific angle. Await returns when command is sent to Hub.
// Turn ~180 degrees
await hub.motorAngleAsync('B', 980, 100, true);
// Continue after the turn
- hub.motorAngleMultiAsync(angle, dutyCycleA = 100, dutyCycleB = 100, wait = false)
Turn both motors (A and B) by specific angle. Await returns when command is sent to Hub.
// Drive forward
await hub.motorAngleMultiAsync(500, 100, 100);
// Continue immediately after command is sent to Hub
Example project
lego-boost-ai has a simple AI and manual controls for Lego Boost.
Tester
Changelog
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
Licensed under the MIT License.