本文整理匯總了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);