MakeCode has a couple of ways to read the capacitive touch inputs.
The first example uses the INPUT code group is pressed
conditional block. It starts as button A
is pressed but you can change this to any of the buttons or cap touch pins. The program below uses a big if
statement block to check each input to see if it is touched. If it is, then it lights the NeoPixel closest to that pad green using blocks from the LIGHT block group. If no pad is touched, the green dots are cleared.
You can change the sensitivity of the touchpads individually. This code sets the sensitivity in an on start
block prior to the forever
loop running.
The final example shows using 4 capacitive touch pads. The on button
event blocks from the INPUT group change a NeoPixel color when touched. This has the benefit of not having to poll for touches in a loop. If button A is pressed, it clears the NeoPixels that have been lit by touches.
Text editor powered by tinymce.