From 167a88bfc8ba986c2e57acc29e3663828c29a816 Mon Sep 17 00:00:00 2001 From: mrmcwethy Date: Tue, 23 Jan 2018 13:28:29 -0700 Subject: [PATCH 1/4] added examples folder and .py files --- examples/acceleration.py | 5 +++++ examples/pixels.py | 35 +++++++++++++++++++++++++++++++++++ examples/shake.py | 5 +++++ examples/tapdetect.py | 22 ++++++++++++++++++++++ examples/tone.py | 9 +++++++++ examples/touched.py | 17 +++++++++++++++++ 6 files changed, 93 insertions(+) create mode 100644 examples/acceleration.py create mode 100644 examples/pixels.py create mode 100644 examples/shake.py create mode 100644 examples/tapdetect.py create mode 100644 examples/tone.py create mode 100644 examples/touched.py diff --git a/examples/acceleration.py b/examples/acceleration.py new file mode 100644 index 0000000..5ea134c --- /dev/null +++ b/examples/acceleration.py @@ -0,0 +1,5 @@ +from adafruit_circuitplayground.express import cpx + +while True: + x, y, z = cpx.acceleration + print(x, y, z) 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/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') From 30d41421f94b83ca67c6fe2adf50f4de62d23e71 Mon Sep 17 00:00:00 2001 From: mrmcwethy Date: Tue, 23 Jan 2018 14:00:24 -0700 Subject: [PATCH 2/4] added simple tap detect example --- examples/tapodetectsimple.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 examples/tapodetectsimple.py diff --git a/examples/tapodetectsimple.py b/examples/tapodetectsimple.py new file mode 100644 index 0000000..ff2c2b7 --- /dev/null +++ b/examples/tapodetectsimple.py @@ -0,0 +1,7 @@ +from adafruit_circuitplayground.express import cpx + +cpx.detect_taps = 1 + +while True: + if cpx.tapped: + print("Single tap detected!") From ec7c9470f70fdb4fa0f9f129d3a917201fb1eb50 Mon Sep 17 00:00:00 2001 From: mrmcwethy Date: Tue, 23 Jan 2018 15:10:16 -0700 Subject: [PATCH 3/4] add time.sleep(0.1) to acceleration.py --- examples/acceleration.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/acceleration.py b/examples/acceleration.py index 5ea134c..b1a15a6 100644 --- a/examples/acceleration.py +++ b/examples/acceleration.py @@ -1,5 +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) From cc44199675c47f5f02de26edf4c5f1cdc322b8f0 Mon Sep 17 00:00:00 2001 From: mrmcwethy Date: Tue, 23 Jan 2018 15:41:44 -0700 Subject: [PATCH 4/4] fixed name of tapdetectsimple.py --- examples/{tapodetectsimple.py => tapdetectsimple.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{tapodetectsimple.py => tapdetectsimple.py} (100%) diff --git a/examples/tapodetectsimple.py b/examples/tapdetectsimple.py similarity index 100% rename from examples/tapodetectsimple.py rename to examples/tapdetectsimple.py