CircuitPython Internal DotStar

This quick-start example builds upon the previous example, but shows how you can create interactivity using capacitive touch. It also demonstrates the built in DotStar LED and how you can change the color on your own.

Copy and paste the code block into using your favorite text editor, and save the file, to run the demo

# Gemma IO demo - captouch to dotstar

import touchio
import busio
import board
import time

dotstar = busio.SPI(board.APA102_SCK, board.APA102_MOSI)
touch0 = touchio.TouchIn(board.A0)
touch1 = touchio.TouchIn(board.A1)
touch2 = touchio.TouchIn(board.A2)

r = g = b = 0

def setPixel(red, green, blue):
    if not dotstar.try_lock():
    print("setting pixel to: %d %d %d" % (red, green, blue))

    data = bytearray([0x00, 0x00, 0x00, 0x00,
                      0xff, blue, green, red,
                      0xff, 0xff, 0xff, 0xff])

while True:
    if touch0.value:
        r = (r+1) % 256
    if touch1.value:
        g = (g+1) % 256
    if touch2.value:
        b = (b+1) % 256

    setPixel(r, g, b)

Each of the three pads will change the color of the built in mini DotStar LED. You can touch each pad in order to see the LED change colors, or you can open up the serial console to see the touches detected and the pixel color printed out.

Last updated on 2017-12-01 at 04.59.09 PM Published on 2017-07-26 at 06.08.30 PM