本文整理汇总了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();
}
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:31,代码来源:i2c-bus-tests.ts
示例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);
开发者ID:stan4cb,项目名称:led-controller,代码行数:31,代码来源:servo.ts
注:本文中的i2c-bus.openSync函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论