pxt-ev3/libs/core/ultrasonic.ts

23 lines
553 B
TypeScript
Raw Normal View History

2017-07-10 16:07:23 +02:00
namespace input {
export class UltraSonicSensor extends internal.UartSensor {
constructor() {
super()
}
_deviceType() {
return DAL.DEVICE_TYPE_ULTRASONIC
2017-07-10 16:07:23 +02:00
}
/** Get distance in mm */
getDistance() {
// it supposedly also has an inch mode, but we stick to mm
this._setMode(0)
return this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff
}
}
//% whenUsed
export const ultrasonic: UltraSonicSensor = new UltraSonicSensor()
}