44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
|
// to try this demo
|
||
|
// npm install @uci/interrupt
|
||
|
// Connect 5V MCP interrupt pin via 3.3 V logic level!!!!! converter to a gpio pin
|
||
|
// Set your SETTINGS below
|
||
|
// npm run inter
|
||
|
|
||
|
const Bus = require('@uci/i2c').Bus,
|
||
|
MCP = require('../src/mcp23008-17'),
|
||
|
// use this require when using your own code
|
||
|
// MCP = require('@uci/mcp')
|
||
|
Interrupt = require('@uci/interrupt')
|
||
|
|
||
|
let bus = new Bus()
|
||
|
|
||
|
// SETTINGS
|
||
|
let ADDR = 0x20
|
||
|
let CHIP = 'MCP23017'
|
||
|
let MS = 300 // so humans can watch the light otherwise set to zero
|
||
|
let pinA = 12
|
||
|
let pinB = 16
|
||
|
|
||
|
let id = `${CHIP} at I2C bus address of 0x${ADDR.toString(16)}`
|
||
|
|
||
|
async function ihandler(port) {
|
||
|
let pin = await this.interruptPin(port, 'PLC')
|
||
|
console.log(`handler fired for ${this.id} on port ${port} pin ${pin}`)
|
||
|
await this.interruptReset(port)
|
||
|
}
|
||
|
|
||
|
let mcp = new MCP[CHIP](bus, ADDR, {
|
||
|
pin_cfg_default: 'toggle_switch',
|
||
|
id: id,
|
||
|
interruptA: new Interrupt(pinA, ihandler),
|
||
|
interruptB: new Interrupt(pinB, ihandler)
|
||
|
});
|
||
|
|
||
|
(async function () {
|
||
|
|
||
|
await mcp.init()
|
||
|
// start will start the
|
||
|
await mcp.start()
|
||
|
|
||
|
})()
|