These are some exercises you can try if you have time to spare. For each exercise, run the code and try to adapt it.
Each of the copper pads at the edge of the board can act as capacitive touch detectors (i.e., a simple version of your phone’s touchscreen). It might be a bit difficult to touch a single pad with your fingers. If you want you can attach an alligator clip to the pad(s).
The code below detects whether pad A1 is touched. If so, it switches on an LED.
import time
import board
import touchio
import neopixel
#You may need to restart your code/board after changing the attached item because
# the capacitive touch code 'calibrates' based on what it sees when it first starts up.
touch_A1 = touchio.TouchIn(board.A1)
touch_A2 = touchio.TouchIn(board.A2)
touch_A3 = touchio.TouchIn(board.A3)
touch_A4 = touchio.TouchIn(board.A4)
touch_A5 = touchio.TouchIn(board.A5)
touch_A6 = touchio.TouchIn(board.A6)
touch_TX = touchio.TouchIn(board.TX)
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10)
while True:
if touch_A1.value:
print("A1 touched!")
pixels[0] = (250, 0, 0)
else:
pixels[0] = (0, 0, 0)
pixels.show()
time.sleep(0.01)
The code below makes the LEDs pulse. Shaking the device increases the pulse rate. When the board is not moving the pulse rate decreases gradually to the base rate.
The code defines multiple parameters (variables):