diff --git a/docs/examples.rst b/docs/examples.rst index 9d11b71..e882b92 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -27,7 +27,7 @@ Ensure your device works with this simple test. :caption: examples/circuitplayground_tone.py :linenos: -.. literalinclude:: ../examples/circuitplayground_touched.py +.. literalinclude:: ../examples/circuitplayground_touch_all.py :caption: examples/circuitplayground_touched.py :linenos: diff --git a/examples/circuitplayground_acceleration.py b/examples/circuitplayground_acceleration.py index 7101769..6b3d618 100644 --- a/examples/circuitplayground_acceleration.py +++ b/examples/circuitplayground_acceleration.py @@ -1,10 +1,12 @@ -"""This example uses the accelerometer on the Circuit Playground. It prints the values. Try moving -the board to see the values change.""" +""" +This example uses the accelerometer on the Circuit Playground. It prints the values. Try moving +the board to see the values change. If you're using Mu, open the plotter to see the values plotted. +""" import time from adafruit_circuitplayground import cp while True: x, y, z = cp.acceleration - print(x, y, z) + print((x, y, z)) time.sleep(0.1) diff --git a/examples/circuitplayground_bluefruit_loud_sound.py b/examples/circuitplayground_bluefruit_loud_sound.py new file mode 100644 index 0000000..198f3be --- /dev/null +++ b/examples/circuitplayground_bluefruit_loud_sound.py @@ -0,0 +1,15 @@ +""" +This example lights up the NeoPixels on a Circuit Playground Bluefruit in response to a loud sound. +Try snapping or clapping near the board to trigger the LEDs. + +NOTE: This example does NOT support Circuit Playground Express. +""" +import time +from adafruit_circuitplayground import cp + +while True: + if cp.loud_sound(): + cp.pixels.fill((50, 0, 50)) + time.sleep(0.2) + else: + cp.pixels.fill((0, 0, 0)) diff --git a/examples/circuitplayground_bluefruit_loud_sound_threshold.py b/examples/circuitplayground_bluefruit_loud_sound_threshold.py new file mode 100644 index 0000000..e982f87 --- /dev/null +++ b/examples/circuitplayground_bluefruit_loud_sound_threshold.py @@ -0,0 +1,15 @@ +""" +This example lights up the NeoPixels on a Circuit Playground Bluefruit in response to a loud sound. +Try snapping or clapping near the board to trigger the LEDs. + +NOTE: This example does NOT support Circuit Playground Express. +""" +import time +from adafruit_circuitplayground import cp + +while True: + if cp.loud_sound(sound_threshold=250): + cp.pixels.fill((50, 0, 50)) + time.sleep(0.2) + else: + cp.pixels.fill((0, 0, 0)) diff --git a/examples/circuitplayground_bluefruit_sound_level.py b/examples/circuitplayground_bluefruit_sound_level.py new file mode 100644 index 0000000..d12d992 --- /dev/null +++ b/examples/circuitplayground_bluefruit_sound_level.py @@ -0,0 +1,12 @@ +""" +This example prints out sound levels using the sound sensor on a Circuit Playground Bluefruit. +Try making sounds towards the board to see the values change. + +NOTE: This example does NOT support Circuit Playground Express. +""" +import time +from adafruit_circuitplayground import cp + +while True: + print("Sound level:", cp.sound_level) + time.sleep(0.1) diff --git a/examples/circuitplayground_bluefruit_sound_level_plotter.py b/examples/circuitplayground_bluefruit_sound_level_plotter.py new file mode 100644 index 0000000..d3d1e08 --- /dev/null +++ b/examples/circuitplayground_bluefruit_sound_level_plotter.py @@ -0,0 +1,14 @@ +""" +This example prints out sound levels using the sound sensor on a Circuit Playground Bluefruit. If +you are using Mu, open the plotter to see the sound level plotted. Try making sounds towards the +board to see the values change. + +NOTE: This example does NOT support Circuit Playground Express. +""" +import time +from adafruit_circuitplayground import cp + +while True: + print("Sound level:", cp.sound_level) + print((cp.sound_level,)) + time.sleep(0.1) diff --git a/examples/circuitplayground_light_neopixels.py b/examples/circuitplayground_light_neopixels.py index 8427e66..68b9edf 100644 --- a/examples/circuitplayground_light_neopixels.py +++ b/examples/circuitplayground_light_neopixels.py @@ -13,9 +13,9 @@ def scale_range(value): - """Scale a value from 0-320 (light range) to 0-10 (the number of NeoPixels). + """Scale a value from 0-320 (light range) to 0-9 (NeoPixel range). Allows remapping light value to pixel position.""" - return int(value / 320 * 10) + return round(value / 320 * 9) while True: diff --git a/examples/circuitplayground_neopixel_0.py b/examples/circuitplayground_neopixel_0.py new file mode 100644 index 0000000..2b2e8f1 --- /dev/null +++ b/examples/circuitplayground_neopixel_0.py @@ -0,0 +1,7 @@ +"""This example lights up the first NeoPixel red.""" +from adafruit_circuitplayground import cp + +cp.pixels.brightness = 0.3 + +while True: + cp.pixels[0] = (255, 0, 0) diff --git a/examples/circuitplayground_neopixels_fill.py b/examples/circuitplayground_neopixels_fill.py new file mode 100644 index 0000000..640cf94 --- /dev/null +++ b/examples/circuitplayground_neopixels_fill.py @@ -0,0 +1,5 @@ +"""This example lights up all the NeoPixel LEDs red.""" +from adafruit_circuitplayground import cp + +while True: + cp.pixels.fill((50, 0, 0)) diff --git a/examples/circuitplayground_shake.py b/examples/circuitplayground_shake.py index 423341a..984f441 100644 --- a/examples/circuitplayground_shake.py +++ b/examples/circuitplayground_shake.py @@ -2,5 +2,5 @@ from adafruit_circuitplayground import cp while True: - if cp.shake(shake_threshold=20): + if cp.shake(): print("Shake detected!") diff --git a/examples/circuitplayground_shake_red_led.py b/examples/circuitplayground_shake_red_led.py new file mode 100644 index 0000000..7399680 --- /dev/null +++ b/examples/circuitplayground_shake_red_led.py @@ -0,0 +1,9 @@ +"""This example flashes the little red LED when the Circuit Playground is shaken.""" +from adafruit_circuitplayground import cp + +while True: + if cp.shake(shake_threshold=20): + print("Shake detected!") + cp.red_led = True + else: + cp.red_led = False diff --git a/examples/circuitplayground_tapdetect.py b/examples/circuitplayground_tapdetect.py index fc1e688..e32aa39 100644 --- a/examples/circuitplayground_tapdetect.py +++ b/examples/circuitplayground_tapdetect.py @@ -1,4 +1,5 @@ """This example prints to the serial console when the board is double-tapped.""" +import time from adafruit_circuitplayground import cp # Change to 1 for single-tap detection. @@ -7,3 +8,4 @@ while True: if cp.tapped: print("Tapped!") + time.sleep(0.05) diff --git a/examples/circuitplayground_tapdetect_single_double.py b/examples/circuitplayground_tapdetect_single_double.py index 77cf024..c1da0bd 100644 --- a/examples/circuitplayground_tapdetect_single_double.py +++ b/examples/circuitplayground_tapdetect_single_double.py @@ -22,3 +22,5 @@ tap_count += 1 print("Reached 2 double-taps!") print("Done.") +while True: + cp.red_led = True diff --git a/examples/circuitplayground_touch_a1.py b/examples/circuitplayground_touch_a1.py new file mode 100644 index 0000000..df59cbf --- /dev/null +++ b/examples/circuitplayground_touch_a1.py @@ -0,0 +1,6 @@ +"""This example prints to the serial console when you touch capacitive touch pad A1.""" +from adafruit_circuitplayground import cp + +while True: + if cp.touch_A1: + print('Touched pad A1') diff --git a/examples/circuitplayground_touched.py b/examples/circuitplayground_touch_all.py similarity index 100% rename from examples/circuitplayground_touched.py rename to examples/circuitplayground_touch_all.py