-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update documentation and package.json for upcoming release 1.3.0
- Loading branch information
1 parent
30bcb67
commit 05848c4
Showing
4 changed files
with
69 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// npm run-script usage | ||
const pigpio = require('../pigpio-client').pigpio({host: process.env.npm_package_config_host}); | ||
|
||
const ready = new Promise((resolve, reject) => { | ||
pigpio.once('connected', resolve); | ||
pigpio.once('error', reject); | ||
}); | ||
|
||
function wait(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
ready.then(async (info) => { | ||
// display information on pigpio and connection status | ||
console.log(JSON.stringify(info,null,2)); | ||
|
||
// get events from a button on GPIO 17 | ||
const button = pigpio.gpio(17); | ||
await button.modeSet('input'); | ||
button.notify((level, tick)=> { | ||
console.log(`Button changed to ${level} at ${tick} usec`) | ||
}); | ||
|
||
// control an LED on GPIO 4 | ||
const led = pigpio.gpio(4); | ||
await led.modeSet('output'); | ||
await led.write(1); // turn on LED | ||
await wait(500); | ||
await led.write(0); // turn off | ||
await wait(500); | ||
|
||
// use waves to blink the LED rapidly (toggle every 100ms) | ||
await led.waveClear(); | ||
await led.waveAddPulse([[1, 0, 100000], [0, 1, 100000]]); | ||
const blinkWave = await led.waveCreate(); | ||
led.waveChainTx([{loop: true}, {waves: [blinkWave]}, {repeat: true}]); | ||
|
||
// wait for 10 seconds, stop the waves | ||
await wait(10000); | ||
await led.waveTxStop(); | ||
pigpio.end(); | ||
}).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters