raspberry pi で、MCP23017 の入力ポートを使う Node.js 版

  • 0
    Like
  • 0
    Comment
    #! /usr/local/bin/node
    //
    //  mcp23017_node_input.js
    //
    //                  May/31/2017
    //
    // ------------------------------------------------------------------
    function read_proc (wire)
    {
        wire.readBytes(0x13, 1, function(err, res)
        {
        console.log (res)
    
        console.log (res[0].toString(16))
        console.log ("*** end ***")
        })
    }
    
    // ------------------------------------------------------------------
    console.log ("*** start ***")
    var i2c = require('i2c')
    const address = 0x20
    var wire = new i2c(address, {device: '/dev/i2c-1'})
        // point to your i2c address, debug provides REPL interface 
    
    wire.writeBytes(0x01, [0xff], function(err, res)
        {
        wire.writeBytes(0x0d, [0xff], function(err, res)
            {
            read_proc (wire)
            })
        })
    
    // ------------------------------------------------------------------