1
0
Fork 0
mirror of https://github.com/kou029w/megabit.git synced 2025-01-30 21:58:04 +00:00
megabit/src/gp2y0e03.ts
2021-07-25 00:03:48 +09:00

22 lines
488 B
TypeScript

import Device from "@chirimen/gp2y0e03";
import { ReadableDevice } from "./Device";
import { I2C, i2c } from "./i2c";
/** Distance (cm) */
export type Distance = number;
export function gp2y0e03(
bus: I2C = i2c(),
address: number = 0x40
): ReadableDevice<number> {
const device = new Device(bus, address);
return {
async read(): Promise<Distance> {
if (device.i2cSlave == null) await device.init();
return device.read();
},
};
}
export default gp2y0e03;