/** * Example 1 from the i2c-bus README file. */ function example1(): void { const i2c1 = openSync(1); const DS1621_ADDR = 0x48, CMD_ACCESS_CONFIG = 0xac, CMD_READ_TEMP = 0xaa, CMD_START_CONVERT = 0xee; // Enter one shot mode (this is a non volatile setting) i2c1.writeByteSync(DS1621_ADDR, CMD_ACCESS_CONFIG, 0x01); // Wait while non volatile memory busy while (i2c1.readByteSync(DS1621_ADDR, CMD_ACCESS_CONFIG) & 0x10) { } // Start temperature conversion i2c1.sendByteSync(DS1621_ADDR, CMD_START_CONVERT); // Wait for temperature conversion to complete while ((i2c1.readByteSync(DS1621_ADDR, CMD_ACCESS_CONFIG) & 0x80) === 0) { } // Display temperature const rawTemp = i2c1.readWordSync(DS1621_ADDR, CMD_READ_TEMP); console.log("temp: " + toCelsius(rawTemp)); i2c1.closeSync(); }
/// <reference path="../typings/tsd.d.ts" /> "use strict"; import * as i2cBus from "i2c-bus"; import Pca9685Driver from "../"; const options = { i2c: i2cBus.openSync(1), address: 0x40, // default value frequency: 50, // default value debug: true }; // pulse lengths in microseconds (theoretically, 1.5 ms // is the middle of a typical servo's range) const pulseLengths: number[] = [ 1300, 1500, 1700 ]; const steeringChannel: number = 0; // variables used in servoLoop var pwm: Pca9685Driver; var nextPulse: number = 0; var timer: NodeJS.Timer; // loop to cycle through pulse lengths function servoLoop() { timer = setTimeout(servoLoop, 500);