add example
This commit is contained in:
parent
ae0ced0055
commit
3b5264cfbd
1 changed files with 17 additions and 0 deletions
17
example.js
Normal file
17
example.js
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const MPR121 = require('./index.js'),
|
||||||
|
mpr121 = new MPR121(0x5A, 1);
|
||||||
|
|
||||||
|
// listen for touch events
|
||||||
|
mpr121.on('touch', (pin) => console.log(`pin ${pin} touched`));
|
||||||
|
|
||||||
|
// listen for release events
|
||||||
|
mpr121.on('release', (pin) => console.log(`pin ${pin} released`));
|
||||||
|
|
||||||
|
// listen for changes to the state of a specific pin
|
||||||
|
mpr121.on(3, (state) => console.log(`pin 3 is ${state ? 'touched' : 'released'}`);
|
||||||
|
|
||||||
|
// check the current state of a specific pin synchronously
|
||||||
|
const state = mpr121.isTouched(2);
|
||||||
|
console.log(`pin 2 is ${state ? 'touched' : 'released'}`);
|
||||||
Loading…
Reference in a new issue