Simple test¶
Ensure your device works with this simple test.
1 2 3 4 5 6 7 8 | import time
from adafruit_circuitplayground.express import cpx
while True:
x, y, z = cpx.acceleration
print(x, y, z)
time.sleep(0.1)
|
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 34 35 | # CircuitPython demo - NeoPixel
import time
from adafruit_circuitplayground.express import cpx
# The number of pixels in the strip
numpix = 10
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) or (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))
def rainbow_cycle(wait):
for j in range(255):
for i in range(cpx.pixels.n):
idx = int((i * 256 / len(cpx.pixels)) + j)
cpx.pixels[i] = wheel(idx & 255)
cpx.pixels.show()
time.sleep(wait)
cpx.pixels.auto_write = False
cpx.pixels.brightness = 0.3
while True:
rainbow_cycle(0.001) # rainbowcycle with 1ms delay per step
|
1 2 3 4 5 | from adafruit_circuitplayground.express import cpx
while True:
if cpx.shake(shake_threshold=20):
print("Shake detected!")
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | from adafruit_circuitplayground.express import cpx
# Set to check for single-taps.
cpx.detect_taps = 1
tap_count = 0
# We're looking for 2 single-taps before moving on.
while tap_count < 2:
if cpx.tapped:
tap_count += 1
print("Reached 2 single-taps!")
# Now switch to checking for double-taps
tap_count = 0
cpx.detect_taps = 2
# We're looking for 2 double-taps before moving on.
while tap_count < 2:
if cpx.tapped:
tap_count += 1
print("Reached 2 double-taps!")
print("Done.")
|
1 2 3 4 5 6 7 | from adafruit_circuitplayground.express import cpx
cpx.detect_taps = 1
while True:
if cpx.tapped:
print("Single tap detected!")
|
1 2 3 4 5 6 7 8 9 | from adafruit_circuitplayground.express import cpx
while True:
if cpx.button_a:
cpx.start_tone(262)
elif cpx.button_b:
cpx.start_tone(294)
else:
cpx.stop_tone()
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | from adafruit_circuitplayground.express import cpx
while True:
if cpx.touch_A1:
print('Touched pad A1')
if cpx.touch_A2:
print('Touched pad A2')
if cpx.touch_A3:
print('Touched pad A3')
if cpx.touch_A4:
print('Touched pad A4')
if cpx.touch_A5:
print('Touched pad A5')
if cpx.touch_A6:
print('Touched pad A6')
if cpx.touch_A7:
print('Touched pad A7')
|