uci-mcp/examples/outputs.js

41 lines
1.2 KiB
JavaScript

/*
*
*
*/
import { MCP230XX } from '../src'
// const TRANSPORT = process.env.TRANSPORT || 'tcp'
const HOST = process.env.BUS_HOST || 'sbc'
const PORT = process.env.BUS_PORT || 1776
const ADDRESS = process.env.DEVICE_ADDR || 39
const CHIP17 = !!process.env.CHIP17 || false
;
(async () => {
let outputs = new MCP230XX({id:'mcp', chip17:CHIP17, address:ADDRESS, bus:{host:HOST, port:PORT}})
console.log(await outputs.socketsInit())
await new Promise((resolve) => setTimeout(resolve,50))
outputs.on('ready:mcp', async ev => {
console.log('mcpready', ev)
// all pins are outputs by default
for (var i = 0; i < 10; i++) {
console.log('pass', i)
await outputs.commands.pin.state.on({pins:'all'})
await outputs.commands.pin.state.on({port:'B', pins:'all'}) // will be ingnored on mcp23008
await new Promise((resolve) => setTimeout(resolve,50))
await outputs.commands.pin.state.off({pins:'all'})
await outputs.commands.pin.state.off({port:'B', pins:'all'}) // will be ingnored on mcp23008
}
process.kill(process.pid, 'SIGTERM')
})
})().catch(err => {
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
})