PoweredUpJS
A Node.js SDK for programming the LEGO® Powered Up platform.
Disclaimer: LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this software.
Getting started
Please install the @powered-up/api
package as described
here.
The following example uses a Smart Move Hub (included in the LEGO® Boost Set 17101) and activates the built-in motor A while the button is held down:
// @ts-check
const {SmartMoveRobot} = require('@powered-up/api');
const {autorun} = require('mobx');
const moveRobot = new SmartMoveRobot();
autorun(() => {
const {buttonPressed, encodedMotorA, rgbLight} = moveRobot;
if (!encodedMotorA || !rgbLight) {
return;
}
if (buttonPressed) {
rgbLight.setColor({red: 0, green: 255, blue: 0});
encodedMotorA.runWithPower(100);
} else {
rgbLight.setColor({red: 255, green: 0, blue: 0});
encodedMotorA.brake();
}
});
You can find some more examples in the demo package.
Implementation status
Smart Move Hub 2 I/O (Robot) | Smart Hub 2 I/O (Robot) | |
---|---|---|
Button | ||
VoltageSensor | ||
CurrentSensor | ✅ Supported | |
RGBLight | ✅ Supported | |
InternalEncodedMotor | ❌ N/A | |
InternalTiltSensor | ||
Motor | ||
EncodedMotor | ⚠️ Not yet implemented | |
VisionSensor | ⚠️ Not yet implemented |
Packages
@powered-up/api
A reactive library for controlling LEGO® Powered Up devices.
Internal packages
@powered-up/ble
A reactive library for managing BLE connections to LEGO® Powered Up hubs.
@powered-up/protocol
A partial implementation of the LEGO® Powered Up BLE protocol in JavaScript.
Related links
Copyright (c) 2018-present, Clemens Akens. Released under the terms of the MIT License.