1var i2c = require('i2c'); 2 3var memaddr = 0x18 4var msgbuf = [0x10, 0xee] 5// led灯 6var sensor = i2c.open({ 7 id: 'sensor', 8 success: function() { 9 console.log('open i2c success') 10 }, 11 fail: function() { 12 console.log('open i2c failed') 13 } 14}); 15 16sensor.write(msgbuf) 17var value = sensor.read(2) 18 19console.log('sensor value is ' + value) 20 21sensor.writeMem(memaddr, msgbuf) 22 23 24var vol = sensor.readMem(memaddr, 2) 25console.log('sensor read mem vol is ' + vol) 26 27 28sensor.close();