more annotations
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
namespace input {
|
||||
|
||||
//% fixedInstances
|
||||
export class UltraSonicSensor extends internal.UartSensor {
|
||||
constructor(port: number) {
|
||||
super(port)
|
||||
@ -9,23 +10,33 @@ namespace input {
|
||||
return DAL.DEVICE_TYPE_ULTRASONIC
|
||||
}
|
||||
|
||||
/** Get distance in mm */
|
||||
getDistance() {
|
||||
/**
|
||||
* Gets the distance from the sonar in millimeters
|
||||
* @param sonar the ultrasonic sensor
|
||||
*/
|
||||
//% help=input/ultrasonic/distance
|
||||
//% block="%sonar|distance"
|
||||
//% blockId=sonarGetDistance
|
||||
//% parts="ultrasonic"
|
||||
//% blockNamespace=input
|
||||
//% weight=65 blockGap=8
|
||||
//% group="Sonar"
|
||||
distance() {
|
||||
// it supposedly also has an inch mode, but we stick to mm
|
||||
this._setMode(0)
|
||||
return this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff
|
||||
}
|
||||
}
|
||||
|
||||
//% whenUsed
|
||||
//% fixedInstance whenUsed block="ultrasonic 1"
|
||||
export const ultrasonic1: UltraSonicSensor = new UltraSonicSensor(1)
|
||||
|
||||
//% whenUsed
|
||||
//% fixedInstance whenUsed block="ultrasonic 1"
|
||||
export const ultrasonic2: UltraSonicSensor = new UltraSonicSensor(2)
|
||||
|
||||
//% whenUsed
|
||||
//% fixedInstance whenUsed block="ultrasonic 1"
|
||||
export const ultrasonic3: UltraSonicSensor = new UltraSonicSensor(3)
|
||||
|
||||
//% whenUsed
|
||||
//% fixedInstance whenUsed block="ultrasonic 1"
|
||||
export const ultrasonic4: UltraSonicSensor = new UltraSonicSensor(4)
|
||||
}
|
||||
|
Reference in New Issue
Block a user