Updated readme
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Nathan Kellenicki 2021-09-14 21:21:00 -07:00
parent 6b44373930
commit 4bfa4d15e5
2 changed files with 74 additions and 74 deletions

View File

@ -24,9 +24,48 @@ Other products that speak the Powered Up protocol include the Duplo App-Controll
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. 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.
### Sample Usage
```javascript
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...");
```
More examples are available in the "examples" directory.
### Documentation
[Full documentation is available here.](https://nathankellenicki.github.io/node-poweredup/)
### Node.js Installation ### Node.js Installation
Node.js v8.0+ required. Node.js v12.0+ required.
```javascript ```javascript
npm install node-poweredup --save npm install node-poweredup --save
@ -83,45 +122,6 @@ In addition, the Hubs themselves have certain built-in features which this libra
* On most Unix systems, you need root permissions to access Bluetooth devices. You may want to [grant the node executable access to the Bluetooth adapter](https://github.com/abandonware/noble#running-without-rootsudo-linux-specific) * On most Unix systems, you need root permissions to access Bluetooth devices. You may want to [grant the node executable access to the Bluetooth adapter](https://github.com/abandonware/noble#running-without-rootsudo-linux-specific)
### Documentation
[Full documentation is available here.](https://nathankellenicki.github.io/node-poweredup/)
### Node.js Sample Usage
```javascript
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...");
```
More examples are available in the "examples" directory.
### Credits ### Credits
Thanks go to Jorge Pereira ([@JorgePe](https://github.com/JorgePe)), Sebastian Raff ([@hobbyquaker](https://github.com/hobbyquaker)), Valentin Heun ([@vheun](https://github.com/vheun)), Johan Korten ([@jakorten](https://github.com/jakorten)), and Andrey Pokhilko ([@undera](https://github.com/undera)) for their various works, contributions, and assistance on figuring out the LEGO Boost, WeDo 2.0, and Powered Up protocols. Thanks go to Jorge Pereira ([@JorgePe](https://github.com/JorgePe)), Sebastian Raff ([@hobbyquaker](https://github.com/hobbyquaker)), Valentin Heun ([@vheun](https://github.com/vheun)), Johan Korten ([@jakorten](https://github.com/jakorten)), and Andrey Pokhilko ([@undera](https://github.com/undera)) for their various works, contributions, and assistance on figuring out the LEGO Boost, WeDo 2.0, and Powered Up protocols.

View File

@ -112,8 +112,41 @@
</ul> </ul>
<p>Other products that speak the Powered Up protocol include the Duplo App-Controlled trains and LEGO Super Mario, both of which are compatible with this library.</p> <p>Other products that speak the Powered Up protocol include the Duplo App-Controlled trains and LEGO Super Mario, both of which are compatible with this library.</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> <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>Sample Usage</h3>
<pre class="prettyprint source lang-javascript"><code>const PoweredUP = require(&quot;node-poweredup&quot;);
const poweredUP = new PoweredUP.PoweredUP();
poweredUP.on(&quot;discover&quot;, async (hub) => { // Wait to discover a Hub
console.log(`Discovered ${hub.name}!`);
await hub.connect(); // Connect to the Hub
const motorA = await hub.waitForDeviceAtPort(&quot;A&quot;); // Make sure a motor is plugged into port A
const motorB = await hub.waitForDeviceAtPort(&quot;B&quot;); // Make sure a motor is plugged into port B
console.log(&quot;Connected&quot;);
while (true) { // Repeat indefinitely
console.log(&quot;Running motor B at speed 50&quot;);
motorB.setPower(50); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
console.log(&quot;Running motor A at speed 100 for 2 seconds&quot;);
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(&quot;Running motor A at speed -30 for 1 second&quot;);
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(&quot;Scanning for Hubs...&quot;);
</code></pre>
<p>More examples are available in the &quot;examples&quot; directory.</p>
<h3>Documentation</h3>
<p><a href="https://nathankellenicki.github.io/node-poweredup/">Full documentation is available here.</a></p>
<h3>Node.js Installation</h3> <h3>Node.js Installation</h3>
<p>Node.js v8.0+ required.</p> <p>Node.js v12.0+ required.</p>
<pre class="prettyprint source lang-javascript"><code>npm install node-poweredup --save <pre class="prettyprint source lang-javascript"><code>npm install node-poweredup --save
</code></pre> </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/abandonware/noble#prerequisites">certain dependencies which may need installed first</a>.</p> <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/abandonware/noble#prerequisites">certain dependencies which may need installed first</a>.</p>
@ -372,39 +405,6 @@
<p>On most Unix systems, you need root permissions to access Bluetooth devices. You may want to <a href="https://github.com/abandonware/noble#running-without-rootsudo-linux-specific">grant the node executable access to the Bluetooth adapter</a></p> <p>On most Unix systems, you need root permissions to access Bluetooth devices. You may want to <a href="https://github.com/abandonware/noble#running-without-rootsudo-linux-specific">grant the node executable access to the Bluetooth adapter</a></p>
</li> </li>
</ul> </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(&quot;node-poweredup&quot;);
const poweredUP = new PoweredUP.PoweredUP();
poweredUP.on(&quot;discover&quot;, async (hub) => { // Wait to discover a Hub
console.log(`Discovered ${hub.name}!`);
await hub.connect(); // Connect to the Hub
const motorA = await hub.waitForDeviceAtPort(&quot;A&quot;); // Make sure a motor is plugged into port A
const motorB = await hub.waitForDeviceAtPort(&quot;B&quot;); // Make sure a motor is plugged into port B
console.log(&quot;Connected&quot;);
while (true) { // Repeat indefinitely
console.log(&quot;Running motor B at speed 50&quot;);
motorB.setPower(50); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
console.log(&quot;Running motor A at speed 100 for 2 seconds&quot;);
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(&quot;Running motor A at speed -30 for 1 second&quot;);
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(&quot;Scanning for Hubs...&quot;);
</code></pre>
<p>More examples are available in the &quot;examples&quot; directory.</p>
<h3>Credits</h3> <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> <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> </article>