2017-07-10 12:37:14 +02:00
|
|
|
namespace input {
|
2017-10-03 08:28:44 +02:00
|
|
|
|
|
|
|
//% fixedInstances
|
2017-07-10 12:37:14 +02:00
|
|
|
export class TouchSensor extends internal.AnalogSensor {
|
2017-07-10 15:16:31 +02:00
|
|
|
button: Button;
|
2017-07-10 12:37:14 +02:00
|
|
|
|
2017-10-24 20:58:52 +02:00
|
|
|
constructor(port: number) {
|
|
|
|
super(port)
|
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() {
|
2017-07-11 16:18:59 +02:00
|
|
|
return DAL.DEVICE_TYPE_TOUCH
|
2017-07-10 13:47:00 +02:00
|
|
|
}
|
2017-07-10 12:37:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//% whenUsed
|
2017-10-24 20:58:52 +02:00
|
|
|
export const touchSensorImpl1: TouchSensor = new TouchSensor(1)
|
|
|
|
//% whenUsed
|
|
|
|
export const touchSensorImpl2: TouchSensor = new TouchSensor(2)
|
|
|
|
//% whenUsed
|
|
|
|
export const touchSensorImpl3: TouchSensor = new TouchSensor(3)
|
|
|
|
//% whenUsed
|
|
|
|
export const touchSensorImpl4: TouchSensor = new TouchSensor(4)
|
|
|
|
|
|
|
|
//% whenUsed block="touch sensor 1" weight=95 fixedInstance
|
|
|
|
export const touchSensor1: Button = touchSensorImpl1.button
|
|
|
|
|
|
|
|
//% whenUsed block="touch sensor 2" weight=95 fixedInstance
|
|
|
|
export const touchSensor2: Button = touchSensorImpl2.button
|
|
|
|
|
|
|
|
//% whenUsed block="touch sensor 3" weight=95 fixedInstance
|
|
|
|
export const touchSensor3: Button = touchSensorImpl3.button
|
2017-07-10 15:26:19 +02:00
|
|
|
|
2017-10-24 20:58:52 +02:00
|
|
|
//% whenUsed block="touch sensor 4" weight=95 fixedInstance
|
|
|
|
export const touchSensor4: Button = touchSensorImpl4.button
|
2017-07-10 12:37:14 +02:00
|
|
|
}
|