diff --git a/examples/acceleration.py b/examples/acceleration.py new file mode 100644 index 0000000..b1a15a6 --- /dev/null +++ b/examples/acceleration.py @@ -0,0 +1,8 @@ +import time +from adafruit_circuitplayground.express import cpx + +while True: + x, y, z = cpx.acceleration + print(x, y, z) + + time.sleep(0.1) diff --git a/examples/pixels.py b/examples/pixels.py new file mode 100644 index 0000000..8c7063f --- /dev/null +++ b/examples/pixels.py @@ -0,0 +1,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 diff --git a/examples/shake.py b/examples/shake.py new file mode 100644 index 0000000..d098219 --- /dev/null +++ b/examples/shake.py @@ -0,0 +1,5 @@ +from adafruit_circuitplayground.express import cpx + +while True: + if cpx.shake(shake_threshold=20): + print("Shake detected!") diff --git a/examples/tapdetect.py b/examples/tapdetect.py new file mode 100644 index 0000000..93189c7 --- /dev/null +++ b/examples/tapdetect.py @@ -0,0 +1,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.") diff --git a/examples/tapdetectsimple.py b/examples/tapdetectsimple.py new file mode 100644 index 0000000..ff2c2b7 --- /dev/null +++ b/examples/tapdetectsimple.py @@ -0,0 +1,7 @@ +from adafruit_circuitplayground.express import cpx + +cpx.detect_taps = 1 + +while True: + if cpx.tapped: + print("Single tap detected!") diff --git a/examples/tone.py b/examples/tone.py new file mode 100644 index 0000000..d544a75 --- /dev/null +++ b/examples/tone.py @@ -0,0 +1,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() diff --git a/examples/touched.py b/examples/touched.py new file mode 100644 index 0000000..655a911 --- /dev/null +++ b/examples/touched.py @@ -0,0 +1,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')