Skip to content

Commit

Permalink
add proper cleanup to the code example in README
Browse files Browse the repository at this point in the history
  • Loading branch information
SillyFreak committed Nov 9, 2018
1 parent 55dc919 commit 2456a8e
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,25 @@ $ npm test
```TypeScript
// Create a hedgehog client instance
let hedgehog = new HedgehogClient('tcp://127.0.0.1:10789');

// Control motors and servos
// hedgehog.move(port, power)
await hedgehog.move(0, 100);
await hedgehog.move(2, 100);

// hedgehog.set_servo(port, enabled, position)
await hedgehog.setServo(0, true, 1023);

// Read sensor values
// hedgehog.getAnalog(0) returns a promise which resolves to the sensor value
// Thus, with async await syntax, we can do:
const value = await hedgehog.getAnalog(0);

// Same with digital sensors
const value = await hedgehog.getDigital(8);
try {
// Control motors and servos
// hedgehog.move(port, power)
await hedgehog.move(0, 100);
await hedgehog.move(2, 100);

// hedgehog.set_servo(port, enabled, position)
await hedgehog.setServo(0, true, 1023);

// Read sensor values
// hedgehog.getAnalog(0) returns a promise which resolves to the sensor value
// Thus, with async await syntax, we can do:
const value = await hedgehog.getAnalog(0);

// Same with digital sensors
const value = await hedgehog.getDigital(8);
} finally {
hedgehog.close();
}
```

### Coding Styleguide
Expand Down

0 comments on commit 2456a8e

Please sign in to comment.