From aaf39d68a2c59574f76384bc3dc7b3036bb4cea4 Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Tue, 7 Aug 2018 12:30:40 +0100 Subject: [PATCH] Front page usage example --- README.md | 14 +++++++++++--- package.json | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 706a09f..abb3aed 100644 --- a/README.md +++ b/README.md @@ -37,14 +37,22 @@ While most Powered UP components and Hubs are compatible with each other, there * Plugging two Boost Tacho Motors into the Powered UP Hub will crash the Hub (This requires a firmware update from LEGO to fix). -### Usage +### Usage Example ```javascript const PoweredUP = require("node-poweredup"); -const pup = new PoweredUP.PoweredUP(); +const poweredUP = new PoweredUP.PoweredUP(); + +poweredUP.on("discover", async (hub) => { // Wait to discover a Hub + await hub.setMotorSpeed("A", 100, 2000); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop + await hub.sleep(1000); // Do nothing for 1 second + await hub.setMotorSpeed("A", -50, 1000); // Run a motor attached to port A for 1 second at 1/2 speed in reverse (-50) then stop + await hub.sleep(1000); // Do nothing for 1 second + await hub.setMotorSpeed("A", 75); // Activate a motor attached to port A at 3/4 speed (75) indefinitely +}); ``` -Examples are available in the "examples" directory. +More examples are available in the "examples" directory. ### Credits diff --git a/package.json b/package.json index 7ee616b..fb15409 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-poweredup", - "version": "1.0.4", + "version": "1.0.5", "description": "A Node.js module to interface with LEGO Powered UP components.", "homepage": "https://github.com/nathankellenicki/node-poweredup/", "main": "dist/poweredup.js",