6. Touchpad

The 6 goldfinger on the front of the mPython Board as touchpads for expansion, indicated as P、Y、T、H、O、N in sequence.


Example - Touch different buttons to light up RGB lights of different colors
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from mpython import *

while True:
    if(touchPad_P.read() < 100):
        rgb[0] = (255,0,0)    # 开灯,设置红色
        rgb[1] = (255,0,0)  # 设定为红色
        rgb[2] = (255,0,0)   # 设置为红色
        rgb.write()
    elif(touchPad_Y.read() < 100):
        rgb[0] = (0,255,0) #关灯
        rgb[1] = (0,255,0)
        rgb[2] = (0,255,0)
        rgb.write()
    elif(touchPad_T.read() < 100):
        rgb[0] = (0,0,255) #关灯
        rgb[1] = (0,0,255)
        rgb[2] = (0,0,255)
        rgb.write()
    elif(touchPad_H.read() < 100):
        rgb[0] = (255,255,0) #关灯
        rgb[1] = (255,255,0)
        rgb[2] = (255,255,0)
        rgb.write()
    elif(touchPad_O.read() < 100):
        rgb[0] = (255,0,255) #关灯
        rgb[1] = (255,0,255)
        rgb[2] = (255,0,255)
        rgb.write()
    elif(touchPad_N.read() < 100):
        rgb[0] = (0,255,255) #关灯
        rgb[1] = (0,255,255)
        rgb[2] = (0,255,255)
        rgb.write()

First, import the mPython module, Try to touch the P gold finger with your finger and use read() to read the value. Observe the changes:

>>> from mpython import *
>>> touchPad_P.read()
643
>>> touchPad_P.read()
8

Note

The control board has 6 touch pads on it, touchPad_P、touchPad_Y、touchPad_T、touchPad_H、touchPad_O、touchPad_N,from left to right, and other touch keys are used as above.