Add ultrasonic and gyro (untested)

This commit is contained in:
Michal Moskal
2017-07-10 15:07:23 +01:00
parent babdf45fc3
commit d3263d8456
5 changed files with 60 additions and 1 deletions

22
libs/core/ultrasonic.ts Normal file
View File

@ -0,0 +1,22 @@
namespace input {
export class UltraSonicSensor extends internal.UartSensor {
constructor() {
super()
}
_deviceType() {
return LMS.DEVICE_TYPE_ULTRASONIC
}
/** 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()
}