pxt-ev3/libs/core/touch.ts
2017-07-10 14:26:19 +01:00

29 lines
624 B
TypeScript

namespace input {
export class TouchSensor extends internal.AnalogSensor {
button: Button;
constructor() {
super()
this.button = new Button()
}
_query() {
return this._readPin6() > 2500 ? 1 : 0
}
_update(prev: number, curr: number) {
this.button.update(curr > 0)
}
_deviceType() {
return LMS.DEVICE_TYPE_TOUCH
}
}
//% whenUsed
export const touchSensorImpl: TouchSensor = new TouchSensor()
//% whenUsed
export const touchSensor: Button = touchSensorImpl.button
}