本文整理汇总了TypeScript中i2c-bus.openSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript openSync函数的具体用法?TypeScript openSync怎么用?TypeScript openSync使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了openSync函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: example1
/**
* 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();
}
示例2: servoLoop
/// <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);