This block requires the micro:bit V2 hardware. If you use this block with a micro:bit v1 board, you will see the 927 error code on the screen.
touch Set Mode
Set the touch mode for a touch pin or touch button.
pins.touchSetMode(TouchTarget.P0, TouchTargetMode.Capacitive)
You can choose which method you want a touch target (pins or logo) to use to detect a touch. There are two methods used for touch sensing on the micro:bit, capacitive or resistive:
- Capacitive touch sensing is when the micro:bit detects a change in the capacitance of a pin or conductive surface (like the touch logo) as you finger touches or comes very near it.
- Resistive sensing detects a flow of current from the pin that is touched to the GND pin. Your body needs a connection to GND (either by touching it or by connecting a wire from it to your clothing) while you touch the input pin to complete a circuit between the two pins.
The default touch mode set for the pins is resistive and the default touch mode for the logo is capacitive.
Paramters
- target: the pin or logo you want to set the touch mode for:
P0
,P1
,P2
, orlogo
. - mode: the mode to use for touch detection:
capacitive
orresistive
.
Example
Set the touch mode for the logo to resistive
.
pins.touchSetMode(TouchTarget.LOGO, TouchTargetMode.Resistive)
input.onLogoEvent(TouchButtonEvent.Pressed, function () {
basic.showString("I can't resist")
})