Skip to content

Example updates. #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
8 changes: 5 additions & 3 deletions examples/circuitplayground_acceleration.py
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions examples/circuitplayground_bluefruit_loud_sound.py
Original file line number Diff line number Diff line change
@@ -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))
15 changes: 15 additions & 0 deletions examples/circuitplayground_bluefruit_loud_sound_threshold.py
Original file line number Diff line number Diff line change
@@ -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))
12 changes: 12 additions & 0 deletions examples/circuitplayground_bluefruit_sound_level.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 14 additions & 0 deletions examples/circuitplayground_bluefruit_sound_level_plotter.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions examples/circuitplayground_light_neopixels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions examples/circuitplayground_neopixel_0.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions examples/circuitplayground_neopixels_fill.py
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 1 addition & 1 deletion examples/circuitplayground_shake.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from adafruit_circuitplayground import cp

while True:
if cp.shake(shake_threshold=20):
if cp.shake():
print("Shake detected!")
9 changes: 9 additions & 0 deletions examples/circuitplayground_shake_red_led.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions examples/circuitplayground_tapdetect.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -7,3 +8,4 @@
while True:
if cp.tapped:
print("Tapped!")
time.sleep(0.05)
2 changes: 2 additions & 0 deletions examples/circuitplayground_tapdetect_single_double.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@
tap_count += 1
print("Reached 2 double-taps!")
print("Done.")
while True:
cp.red_led = True
6 changes: 6 additions & 0 deletions examples/circuitplayground_touch_a1.py
Original file line number Diff line number Diff line change
@@ -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')