import board # pin definitions import time # time functions import touchio # capacitivectouch library import pulseio # pwm library import adafruit_dotstar # dotstar rgb led library # One dotstar soldered on the board dot = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Built in red LED led = pulseio.PWMOut(board.D13, frequency=5000, duty_cycle=0) led.duty_cycle = 0 # initially off # Capacitive touch on A2 touch = touchio.TouchIn(board.A2) # Helper to give us a nice color swirl def wheel(pos): # Input a value 0 to 255 to get a color value. # The colours are a transition r - g - b - back to r. if (pos < 0): return [0, 0, 0] if (pos > 255): return [0, 0, 0] if (pos < 85): return [int(pos * 3), int(255 - (pos*3)), 0] elif (pos < 170): pos -= 85 return [int(255 - pos*3), 0, int(pos*3)] else: pos -= 170 return [0, int(pos*3), int(255 - pos*3)] ######################### MAIN LOOP ############################## i = 0 # a variable to keep track of time while True: time.sleep(.01) # wait 0.01 seconds. if this isn't here the code might run too fast i = (i+1) % 256 # run from 0 to 255 dot[0] = wheel(i & 255) # set the color of the dotstar, [red green blue] led.duty_cycle = i*255 # duty_cycle can be 0 to 65535 if i%100==0: # if i is divisible by 100 # printing at this slow speed because sending too often chokes the computer print("A2 touch: %d" % touch.raw_value, end="\n") # print the value of the cap touch sensor on pin A2