504 lines
23 KiB
HTML
504 lines
23 KiB
HTML
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width">
|
|
<title>node-poweredup Index</title>
|
|
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
|
|
|
|
<link type="text/css" rel="stylesheet" href="styles/site.simplex.css">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="navbar navbar-default navbar-fixed-top navbar-inverse">
|
|
<div class="container">
|
|
<div class="navbar-header">
|
|
<a class="navbar-brand" href="index.html">node-poweredup</a>
|
|
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
</button>
|
|
</div>
|
|
<div class="navbar-collapse collapse" id="topNavigation">
|
|
<ul class="nav navbar-nav">
|
|
|
|
<li class="dropdown">
|
|
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
|
|
<ul class="dropdown-menu ">
|
|
<li><a href="AbsoluteMotor.html">AbsoluteMotor</a></li><li><a href="BaseHub.html">BaseHub</a></li><li><a href="BasicMotor.html">BasicMotor</a></li><li><a href="BoostMoveHub.html">BoostMoveHub</a></li><li><a href="ColorDistanceSensor.html">ColorDistanceSensor</a></li><li><a href="ControlPlusHub.html">ControlPlusHub</a></li><li><a href="CurrentSensor.html">CurrentSensor</a></li><li><a href="Device.html">Device</a></li><li><a href="DuploTrainBase.html">DuploTrainBase</a></li><li><a href="DuploTrainBaseColorSensor.html">DuploTrainBaseColorSensor</a></li><li><a href="DuploTrainBaseMotor.html">DuploTrainBaseMotor</a></li><li><a href="DuploTrainBaseSpeaker.html">DuploTrainBaseSpeaker</a></li><li><a href="DuploTraniBaseSpeedometer.html">DuploTraniBaseSpeedometer</a></li><li><a href="Hub.html">Hub</a></li><li><a href="HubLED.html">HubLED</a></li><li><a href="Light.html">Light</a></li><li><a href="LPF2Hub.html">LPF2Hub</a></li><li><a href="MediumLinearMotor.html">MediumLinearMotor</a></li><li><a href="MotionSensor.html">MotionSensor</a></li><li><a href="MoveHub.html">MoveHub</a></li><li><a href="MoveHubMediumLinearMotor.html">MoveHubMediumLinearMotor</a></li><li><a href="MoveHubTiltSensor.html">MoveHubTiltSensor</a></li><li><a href="PiezoBuzzer.html">PiezoBuzzer</a></li><li><a href="PUPHub.html">PUPHub</a></li><li><a href="PUPRemote.html">PUPRemote</a></li><li><a href="RemoteControl.html">RemoteControl</a></li><li><a href="RemoteControlButton.html">RemoteControlButton</a></li><li><a href="SimpleMediumLinearMotor.html">SimpleMediumLinearMotor</a></li><li><a href="TachoMotor.html">TachoMotor</a></li><li><a href="TechnicColorSensor.html">TechnicColorSensor</a></li><li><a href="TechnicDistanceSensor.html">TechnicDistanceSensor</a></li><li><a href="TechnicForceSensor.html">TechnicForceSensor</a></li><li><a href="TechnicLargeAngularMotor.html">TechnicLargeAngularMotor</a></li><li><a href="TechnicLargeLinearMotor.html">TechnicLargeLinearMotor</a></li><li><a href="TechnicMediumAngularMotor.html">TechnicMediumAngularMotor</a></li><li><a href="TechnicMediumHub.html">TechnicMediumHub</a></li><li><a href="TechnicMediumHubAccelerometerSensor.html">TechnicMediumHubAccelerometerSensor</a></li><li><a href="TechnicMediumHubGyroSensor.html">TechnicMediumHubGyroSensor</a></li><li><a href="TechnicMediumHubTiltSensor.html">TechnicMediumHubTiltSensor</a></li><li><a href="TechnicXLargeLinearMotor.html">TechnicXLargeLinearMotor</a></li><li><a href="TiltSensor.html">TiltSensor</a></li><li><a href="TrainMotor.html">TrainMotor</a></li><li><a href="VoltageSensor.html">VoltageSensor</a></li><li><a href="WeDo2SmartHub.html">WeDo2SmartHub</a></li>
|
|
</ul>
|
|
</li>
|
|
|
|
<li class="dropdown">
|
|
<a href="events.list.html" class="dropdown-toggle" data-toggle="dropdown">Events<b class="caret"></b></a>
|
|
<ul class="dropdown-menu ">
|
|
<li><a href="AbsoluteMotor.html#event:absolute">AbsoluteMotor#event:absolute</a></li><li><a href="AbsoluteMotor.html#event:rotate">AbsoluteMotor#event:rotate</a></li><li><a href="BoostMoveHub.html#event:attach">BoostMoveHub#event:attach</a></li><li><a href="BoostMoveHub.html#event:button">BoostMoveHub#event:button</a></li><li><a href="BoostMoveHub.html#event:detach">BoostMoveHub#event:detach</a></li><li><a href="BoostMoveHub.html#event:disconnect">BoostMoveHub#event:disconnect</a></li><li><a href="ColorDistanceSensor.html#event:color">ColorDistanceSensor#event:color</a></li><li><a href="ColorDistanceSensor.html#event:colorAndDistance">ColorDistanceSensor#event:colorAndDistance</a></li><li><a href="ColorDistanceSensor.html#event:distance">ColorDistanceSensor#event:distance</a></li><li><a href="ControlPlusHub.html#event:attach">ControlPlusHub#event:attach</a></li><li><a href="ControlPlusHub.html#event:button">ControlPlusHub#event:button</a></li><li><a href="ControlPlusHub.html#event:detach">ControlPlusHub#event:detach</a></li><li><a href="ControlPlusHub.html#event:disconnect">ControlPlusHub#event:disconnect</a></li><li><a href="CurrentSensor.html#event:current">CurrentSensor#event:current</a></li><li><a href="DuploTrainBase.html#event:button">DuploTrainBase#event:button</a></li><li><a href="DuploTrainBaseColorSensor.html#event:color">DuploTrainBaseColorSensor#event:color</a></li><li><a href="DuploTrainBaseColorSensor.html#event:reflect">DuploTrainBaseColorSensor#event:reflect</a></li><li><a href="DuploTrainBaseColorSensor.html#event:rgb">DuploTrainBaseColorSensor#event:rgb</a></li><li><a href="DuploTrainBaseSpeedometer.html#event:speed">DuploTrainBaseSpeedometer#event:speed</a></li><li><a href="Hub.html#event:attach">Hub#event:attach</a></li><li><a href="Hub.html#event:button">Hub#event:button</a></li><li><a href="Hub.html#event:detach">Hub#event:detach</a></li><li><a href="Hub.html#event:disconnect">Hub#event:disconnect</a></li><li><a href="LPF2Hub.html#event:button">LPF2Hub#event:button</a></li><li><a href="MediumLinearMotor.html#event:rotate">MediumLinearMotor#event:rotate</a></li><li><a href="MotionSensor.html#event:distance">MotionSensor#event:distance</a></li><li><a href="MoveHub.html#event:button">MoveHub#event:button</a></li><li><a href="MoveHubMediumLinearMotor.html#event:rotate">MoveHubMediumLinearMotor#event:rotate</a></li><li><a href="MoveHubTiltSensor.html#event:tilt">MoveHubTiltSensor#event:tilt</a></li><li><a href="PUPHub.html#event:attach">PUPHub#event:attach</a></li><li><a href="PUPHub.html#event:button">PUPHub#event:button</a></li><li><a href="PUPHub.html#event:detach">PUPHub#event:detach</a></li><li><a href="PUPHub.html#event:disconnect">PUPHub#event:disconnect</a></li><li><a href="PUPRemote.html#event:attach">PUPRemote#event:attach</a></li><li><a href="PUPRemote.html#event:button">PUPRemote#event:button</a></li><li><a href="PUPRemote.html#event:detach">PUPRemote#event:detach</a></li><li><a href="PUPRemote.html#event:disconnect">PUPRemote#event:disconnect</a></li><li><a href="RemoteControl.html#event:button">RemoteControl#event:button</a></li><li><a href="RemoteControlButton.html#event:button">RemoteControlButton#event:button</a></li><li><a href="TachoMotor.html#event:rotate">TachoMotor#event:rotate</a></li><li><a href="TechnicColorSensor.html#event:ambient">TechnicColorSensor#event:ambient</a></li><li><a href="TechnicColorSensor.html#event:color">TechnicColorSensor#event:color</a></li><li><a href="TechnicColorSensor.html#event:reflect">TechnicColorSensor#event:reflect</a></li><li><a href="TechnicDistanceSensor.html#event:distance">TechnicDistanceSensor#event:distance</a></li><li><a href="TechnicDistanceSensor.html#event:fastDistance">TechnicDistanceSensor#event:fastDistance</a></li><li><a href="TechnicForceSensor.html#event:force">TechnicForceSensor#event:force</a></li><li><a href="TechnicForceSensor.html#event:tapped">TechnicForceSensor#event:tapped</a></li><li><a href="TechnicForceSensor.html#event:touch">TechnicForceSensor#event:touch</a></li><li><a href="TechnicLargeAngularMotor.html#event:absolute">TechnicLargeAngularMotor#event:absolute</a></li><li><a href="TechnicLargeAngularMotor.html#event:rotate">TechnicLargeAngularMotor#event:rotate</a></li><li><a href="TechnicLargeLinearMotor.html#event:absolute">TechnicLargeLinearMotor#event:absolute</a></li><li><a href="TechnicLargeLinearMotor.html#event:rotate">TechnicLargeLinearMotor#event:rotate</a></li><li><a href="TechnicMediumAngularMotor.html#event:absolute">TechnicMediumAngularMotor#event:absolute</a></li><li><a href="TechnicMediumAngularMotor.html#event:rotate">TechnicMediumAngularMotor#event:rotate</a></li><li><a href="TechnicMediumHub.html#event:button">TechnicMediumHub#event:button</a></li><li><a href="TechnicMediumHubAccelerometerSensor.html#event:accel">TechnicMediumHubAccelerometerSensor#event:accel</a></li><li><a href="TechnicMediumHubGyroSensor.html#event:gyro">TechnicMediumHubGyroSensor#event:gyro</a></li><li><a href="TechnicMediumHubTiltSensor.html#event:tilt">TechnicMediumHubTiltSensor#event:tilt</a></li><li><a href="TechnicXLargeLinearMotor.html#event:absolute">TechnicXLargeLinearMotor#event:absolute</a></li><li><a href="TechnicXLargeLinearMotor.html#event:rotate">TechnicXLargeLinearMotor#event:rotate</a></li><li><a href="TiltSensor.html#event:tilt">TiltSensor#event:tilt</a></li><li><a href="VoltageSensor.html#event:voltage">VoltageSensor#event:voltage</a></li><li><a href="WeDo2SmartHub.html#event:button">WeDo2SmartHub#event:button</a></li>
|
|
</ul>
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<div class="col-sm-3 col-md-3">
|
|
<form class="navbar-form" role="search">
|
|
<div class="input-group">
|
|
<input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
|
|
<div class="input-group-btn">
|
|
<button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="container" id="toc-content">
|
|
<div class="row">
|
|
|
|
|
|
<div class="col-md-8">
|
|
|
|
<div id="main">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section class="readme-section">
|
|
<article><p><a href="https://drone.kellenicki.com/nkellenicki/node-poweredup"><img src="https://drone.kellenicki.com/api/badges/nkellenicki/node-poweredup/status.svg" alt="Drone"></a><br>
|
|
<a href="https://www.npmjs.com/package/node-poweredup"><img src="https://img.shields.io/npm/v/node-poweredup.svg?style=flat" alt="NPM Version"></a></p>
|
|
<h1><strong>node-poweredup</strong> - A Javascript module to interface with LEGO Powered Up components.</h1>
|
|
<h3>Announcements</h3>
|
|
<p><em>Important</em>: v6.0.0 is a complete re-architecting of this library. Improvements include proper device and mode support through an external Device object, correct handling of firmware features, and promise-based functionality for interfacing with device attachments. Although many new features were added, existing code will almost surely break upon upgrade.</p>
|
|
<h3>Introduction</h3>
|
|
<p>LEGO Powered Up is the successor to Power Functions, the system for adding electronics to LEGO models. Powered Up is a collection of ranges - starting with LEGO Education WeDo 2.0 released in 2016, LEGO Boost released in 2017, LEGO Powered Up released in 2018, LEGO Technic CONTROL+ released in 2019, and LEGO Education SPIKE Prime released in 2020. It also includes the 2018 Duplo App-Controlled Train sets.</p>
|
|
<p>This library allows communication and control of Powered Up devices and peripherals via Javascript, both from Node.js and from the browser using Web Bluetooth.</p>
|
|
<h3>Node.js Installation</h3>
|
|
<p>Node.js v8.0+ required.</p>
|
|
<pre class="prettyprint source lang-javascript"><code>npm install node-poweredup --save
|
|
</code></pre>
|
|
<p>node-poweredup uses the Noble BLE library by Sandeep Mistry. On macOS everything should function out of the box. On Linux and Windows there are <a href="https://github.com/noble/noble#prerequisites">certain dependencies which may need installed first</a>.</p>
|
|
<p>Note: node-poweredup has been tested on macOS 10.15 and Debian/Raspbian on the Raspberry Pi 3 Model B.</p>
|
|
<h3>Compatibility</h3>
|
|
<p>While most Powered Up components and Hubs are compatible with each other, there are exceptions. For example, there is limited backwards compatibility between newer components and the WeDo 2.0 Smart Hub. However WeDo 2.0 components are fully forwards compatible with newer Hubs.</p>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Device Name</th>
|
|
<th>Product Code</th>
|
|
<th>Type</th>
|
|
<th>WeDo 2.0 Smart Hub</th>
|
|
<th>Boost Move Hub</th>
|
|
<th>Powered Up Hub</th>
|
|
<th>Control+ Hub</th>
|
|
<th>Availability</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>WeDo 2.0 Tilt Sensor</td>
|
|
<td><a href="https://brickset.com/sets/45305-1/">45305</a></td>
|
|
<td>Sensor</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/45300-1/">45300</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>WeDo 2.0 Motion Sensor</td>
|
|
<td><a href="https://brickset.com/sets/45304-1/">45304</a></td>
|
|
<td>Sensor</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/45300-1/">45300</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>WeDo 2.0 Medium Motor</td>
|
|
<td><a href="https://brickset.com/sets/45303-1/">45303</a></td>
|
|
<td>Motor</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/45300-1/">45300</a><br /> <a href="https://brickset.com/sets/76112-1/">76112</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Boost Color and Distance Sensor</td>
|
|
<td><a href="https://brickset.com/sets/88007-1/">88007</a></td>
|
|
<td>Sensor</td>
|
|
<td><em>Partial</em></td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/17101-1/">17101</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Boost Tacho Motor</td>
|
|
<td><a href="https://brickset.com/sets/88008-1/">88008</a></td>
|
|
<td>Motor/Sensor</td>
|
|
<td><em>Partial</em></td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/17101-1/">17101</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Powered Up Train Motor</td>
|
|
<td><a href="https://brickset.com/sets/88011-1/">88011</a></td>
|
|
<td>Motor</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Powered Up LED Lights</td>
|
|
<td><a href="https://brickset.com/sets/88005-1/">88005</a></td>
|
|
<td>Light</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/88005-1/">88005</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Control+ Large Motor</td>
|
|
<td>22169</td>
|
|
<td>Motor/Sensor</td>
|
|
<td><em>Partial</em></td>
|
|
<td>No</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/42099-1/">42099</a><br /><a href="https://brickset.com/sets/42100-1/">42100</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Control+ XLarge Motor</td>
|
|
<td>22172</td>
|
|
<td>Motor/Sensor</td>
|
|
<td><em>Partial</em></td>
|
|
<td>No</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/42099-1/">42099</a><br /><a href="https://brickset.com/sets/42100-1/">42100</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>SPIKE Prime Medium Motor</td>
|
|
<td>45678</td>
|
|
<td>Motor/Sensor</td>
|
|
<td><em>Partial</em></td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/45678-1/">45678</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>SPIKE Prime Large Motor</td>
|
|
<td>45678</td>
|
|
<td>Motor/Sensor</td>
|
|
<td><em>Partial</em></td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/45678-1/">45678</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>SPIKE Prime Color Sensor</td>
|
|
<td>45678</td>
|
|
<td>Sensor</td>
|
|
<td>No</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/45678-1/">45678</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>SPIKE Prime Distance Sensor</td>
|
|
<td>45678</td>
|
|
<td>Sensor</td>
|
|
<td>No</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/45678-1/">45678</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>SPIKE Prime Force Sensor</td>
|
|
<td>45678</td>
|
|
<td>Sensor</td>
|
|
<td>No</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td>Yes</td>
|
|
<td><a href="https://brickset.com/sets/45678-1/">45678</a></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>In addition, the Hubs themselves have certain built-in features which this library exposes.</p>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Hub Name</th>
|
|
<th>Product Code</th>
|
|
<th>Built-In Features</th>
|
|
<th>Availability</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>WeDo 2.0 Smart hub</td>
|
|
<td><a href="https://brickset.com/sets/45301-1/">45301</a></td>
|
|
<td>RGB LED<br />Piezo Buzzer<br />Button</td>
|
|
<td><a href="https://brickset.com/sets/45300-1/">45300</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Boost Move Hub</td>
|
|
<td><a href="https://brickset.com/sets/88006-1/">88006</a></td>
|
|
<td>RGB LED<br />Tilt Sensor<br />2x Tacho Motors<br />Button</td>
|
|
<td><a href="https://brickset.com/sets/17101-1/">17101</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Powered Up Hub</td>
|
|
<td><a href="https://brickset.com/sets/88009-1/">88009</a></td>
|
|
<td>RGB LED<br />Button</td>
|
|
<td><a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a><br /><a href="https://brickset.com/sets/76112-1/">76112</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Powered Up Remote</td>
|
|
<td><a href="https://brickset.com/sets/88010-1/">88010</a></td>
|
|
<td>RGB LED<br />Left and Right Control Buttons<br />Button</td>
|
|
<td><a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Duplo Train Base</td>
|
|
<td>28743</td>
|
|
<td>RGB LED/Headlights<br />Speaker<br />Speedometer<br />Motor<br />Color and Distance Sensor<br />Button</td>
|
|
<td><a href="https://brickset.com/sets/10874-1/">10874</a><br /><a href="https://brickset.com/sets/10875-1/">10875</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Control+ Hub</td>
|
|
<td>22127</td>
|
|
<td>RGB LED<br />Button<br />Tilt Sensor<br />Accelerometer</td>
|
|
<td><a href="https://brickset.com/sets/42099-1/">42099</a><br /><a href="https://brickset.com/sets/42100-1/">42100</a></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h3>Known Issues and Limitations</h3>
|
|
<ul>
|
|
<li>
|
|
<p>The WeDo 2.0 Smart Hub uses an older firmware which is no longer being updated. As a result, only certain motors and sensors work with it. See the table above.</p>
|
|
</li>
|
|
<li>
|
|
<p>When used with the Boost Move Hub, the Control+ Motors do not currently accept commands (This is a known but which requires a firmware update from Lego to fix)</p>
|
|
</li>
|
|
<li>
|
|
<p>The SPIKE Prime Hub does not use Bluetooth Low Energy, so is not supported via this library. It is recommended you use MicroPython and Bluetooth Classic to develop for this Hub.</p>
|
|
</li>
|
|
</ul>
|
|
<h3>Documentation</h3>
|
|
<p><a href="https://nathankellenicki.github.io/node-poweredup/">Full documentation is available here.</a></p>
|
|
<h3>Node.js Sample Usage</h3>
|
|
<pre class="prettyprint source lang-javascript"><code>const PoweredUP = require("node-poweredup");
|
|
const poweredUP = new PoweredUP.PoweredUP();
|
|
|
|
poweredUP.on("discover", async (hub) => { // Wait to discover a Hub
|
|
console.log(`Discovered ${hub.name}!`);
|
|
await hub.connect(); // Connect to the Hub
|
|
const motorA = await hub.waitForDeviceAtPort("A"); // Make sure a motor is plugged into port A
|
|
const motorB = await hub.waitForDeviceAtPort("B"); // Make sure a motor is plugged into port B
|
|
console.log("Connected");
|
|
|
|
while (true) { // Repeat indefinitely
|
|
console.log("Running motor B at speed 50");
|
|
motorB.setPower(50); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
|
|
console.log("Running motor A at speed 100 for 2 seconds");
|
|
motorA.setPower(100); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop
|
|
await hub.sleep(2000);
|
|
motorA.brake();
|
|
await hub.sleep(1000); // Do nothing for 1 second
|
|
console.log("Running motor A at speed -30 for 1 second");
|
|
motorA.setPower(-30); // Run a motor attached to port A for 2 seconds at 1/2 speed in reverse (-50) then stop
|
|
await hub.sleep(2000);
|
|
motorA.brake();
|
|
await hub.sleep(1000); // Do nothing for 1 second
|
|
}
|
|
});
|
|
|
|
poweredUP.scan(); // Start scanning for Hubs
|
|
console.log("Scanning for Hubs...");
|
|
</code></pre>
|
|
<p>More examples are available in the "examples" directory.</p>
|
|
<h3>Credits</h3>
|
|
<p>Thanks go to Jorge Pereira (<a href="https://github.com/JorgePe">@JorgePe</a>), Sebastian Raff (<a href="https://github.com/hobbyquaker">@hobbyquaker</a>), Valentin Heun (<a href="https://github.com/vheun">@vheun</a>), Johan Korten (<a href="https://github.com/jakorten">@jakorten</a>), and Andrey Pokhilko (<a href="https://github.com/undera">@undera</a>) for their various works, contributions, and assistance on figuring out the LEGO Boost, WeDo 2.0, and Powered Up protocols.</p></article>
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="clearfix"></div>
|
|
|
|
|
|
<div class="col-md-3">
|
|
<div id="toc" class="col-md-3 hidden-xs hidden-sm hidden-md"></div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="modal fade" id="searchResults">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
|
<h4 class="modal-title">Search results</h4>
|
|
</div>
|
|
<div class="modal-body"></div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
|
</div>
|
|
</div><!-- /.modal-content -->
|
|
</div><!-- /.modal-dialog -->
|
|
</div>
|
|
|
|
|
|
<footer>
|
|
|
|
|
|
<span class="copyright">
|
|
node-poweredup by Nathan Kellenicki licensed under the MIT license.
|
|
</span>
|
|
|
|
<span class="jsdoc-message">
|
|
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a>
|
|
|
|
on Sun May 31st 2020
|
|
|
|
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
|
|
</span>
|
|
</footer>
|
|
|
|
<script src="scripts/docstrap.lib.js"></script>
|
|
<script src="scripts/toc.js"></script>
|
|
|
|
<script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
|
|
|
|
|
|
<script>
|
|
$( function () {
|
|
$( "[id*='$']" ).each( function () {
|
|
var $this = $( this );
|
|
|
|
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
|
|
} );
|
|
|
|
$( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
|
|
var $this = $( this );
|
|
|
|
var example = $this.find( "code" );
|
|
exampleText = example.html();
|
|
var lang = /{@lang (.*?)}/.exec( exampleText );
|
|
if ( lang && lang[1] ) {
|
|
exampleText = exampleText.replace( lang[0], "" );
|
|
example.html( exampleText );
|
|
lang = lang[1];
|
|
} else {
|
|
var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
|
|
lang = langClassMatch ? langClassMatch[1] : "javascript";
|
|
}
|
|
|
|
if ( lang ) {
|
|
|
|
$this
|
|
.addClass( "sunlight-highlight-" + lang )
|
|
.addClass( "linenums" )
|
|
.html( example.html() );
|
|
|
|
}
|
|
} );
|
|
|
|
Sunlight.highlightAll( {
|
|
lineNumbers : true,
|
|
showMenu : true,
|
|
enableDoclinks : true
|
|
} );
|
|
|
|
$.catchAnchorLinks( {
|
|
navbarOffset: 10
|
|
} );
|
|
$( "#toc" ).toc( {
|
|
anchorName : function ( i, heading, prefix ) {
|
|
return $( heading ).attr( "id" ) || ( prefix + i );
|
|
},
|
|
selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
|
|
showAndHide : false,
|
|
smoothScrolling: true
|
|
} );
|
|
|
|
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
|
|
$( '.dropdown-toggle' ).dropdown();
|
|
|
|
$( "table" ).each( function () {
|
|
var $this = $( this );
|
|
$this.addClass('table');
|
|
} );
|
|
|
|
} );
|
|
</script>
|
|
|
|
|
|
|
|
<!--Navigation and Symbol Display-->
|
|
|
|
|
|
<!--Google Analytics-->
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
$(document).ready(function() {
|
|
SearcherDisplay.init();
|
|
});
|
|
</script>
|
|
|
|
|
|
</body>
|
|
</html> |