pxt-ev3/libs/core/touch.ts

29 lines
624 B
TypeScript
Raw Normal View History

2017-07-10 12:37:14 +02:00
namespace input {
export class TouchSensor extends internal.AnalogSensor {
2017-07-10 15:16:31 +02:00
button: Button;
2017-07-10 12:37:14 +02:00
constructor() {
super()
2017-07-10 15:16:31 +02:00
this.button = new Button()
2017-07-10 12:37:14 +02:00
}
_query() {
return this._readPin6() > 2500 ? 1 : 0
}
_update(prev: number, curr: number) {
this.button.update(curr > 0)
}
2017-07-10 13:47:00 +02:00
_deviceType() {
return DAL.DEVICE_TYPE_TOUCH
2017-07-10 13:47:00 +02:00
}
2017-07-10 12:37:14 +02:00
}
//% whenUsed
2017-07-10 15:26:19 +02:00
export const touchSensorImpl: TouchSensor = new TouchSensor()
//% whenUsed
export const touchSensor: Button = touchSensorImpl.button
2017-07-10 12:37:14 +02:00
}