This commit is contained in:
parent
6b44373930
commit
4bfa4d15e5
80
README.md
80
README.md
@ -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.
|
||||
|
||||
### 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 v8.0+ required.
|
||||
Node.js v12.0+ required.
|
||||
|
||||
```javascript
|
||||
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)
|
||||
|
||||
### 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
|
||||
|
||||
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.
|
||||
|
@ -112,8 +112,41 @@
|
||||
</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>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("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>Documentation</h3>
|
||||
<p><a href="https://nathankellenicki.github.io/node-poweredup/">Full documentation is available here.</a></p>
|
||||
<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
|
||||
</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>
|
||||
@ -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>
|
||||
</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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user