Skip to content

Commit 4663b60

Browse files
authored
Merge pull request #82 from kattni/example-updates
Example updates.
2 parents fc2c9d6 + fdf4fdf commit 4663b60

15 files changed

+96
-7
lines changed

docs/examples.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Ensure your device works with this simple test.
2727
:caption: examples/circuitplayground_tone.py
2828
:linenos:
2929

30-
.. literalinclude:: ../examples/circuitplayground_touched.py
30+
.. literalinclude:: ../examples/circuitplayground_touch_all.py
3131
:caption: examples/circuitplayground_touched.py
3232
:linenos:
3333

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
"""This example uses the accelerometer on the Circuit Playground. It prints the values. Try moving
2-
the board to see the values change."""
1+
"""
2+
This example uses the accelerometer on the Circuit Playground. It prints the values. Try moving
3+
the board to see the values change. If you're using Mu, open the plotter to see the values plotted.
4+
"""
35
import time
46
from adafruit_circuitplayground import cp
57

68
while True:
79
x, y, z = cp.acceleration
8-
print(x, y, z)
10+
print((x, y, z))
911

1012
time.sleep(0.1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
This example lights up the NeoPixels on a Circuit Playground Bluefruit in response to a loud sound.
3+
Try snapping or clapping near the board to trigger the LEDs.
4+
5+
NOTE: This example does NOT support Circuit Playground Express.
6+
"""
7+
import time
8+
from adafruit_circuitplayground import cp
9+
10+
while True:
11+
if cp.loud_sound():
12+
cp.pixels.fill((50, 0, 50))
13+
time.sleep(0.2)
14+
else:
15+
cp.pixels.fill((0, 0, 0))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
This example lights up the NeoPixels on a Circuit Playground Bluefruit in response to a loud sound.
3+
Try snapping or clapping near the board to trigger the LEDs.
4+
5+
NOTE: This example does NOT support Circuit Playground Express.
6+
"""
7+
import time
8+
from adafruit_circuitplayground import cp
9+
10+
while True:
11+
if cp.loud_sound(sound_threshold=250):
12+
cp.pixels.fill((50, 0, 50))
13+
time.sleep(0.2)
14+
else:
15+
cp.pixels.fill((0, 0, 0))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
This example prints out sound levels using the sound sensor on a Circuit Playground Bluefruit.
3+
Try making sounds towards the board to see the values change.
4+
5+
NOTE: This example does NOT support Circuit Playground Express.
6+
"""
7+
import time
8+
from adafruit_circuitplayground import cp
9+
10+
while True:
11+
print("Sound level:", cp.sound_level)
12+
time.sleep(0.1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
This example prints out sound levels using the sound sensor on a Circuit Playground Bluefruit. If
3+
you are using Mu, open the plotter to see the sound level plotted. Try making sounds towards the
4+
board to see the values change.
5+
6+
NOTE: This example does NOT support Circuit Playground Express.
7+
"""
8+
import time
9+
from adafruit_circuitplayground import cp
10+
11+
while True:
12+
print("Sound level:", cp.sound_level)
13+
print((cp.sound_level,))
14+
time.sleep(0.1)

examples/circuitplayground_light_neopixels.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414

1515
def scale_range(value):
16-
"""Scale a value from 0-320 (light range) to 0-10 (the number of NeoPixels).
16+
"""Scale a value from 0-320 (light range) to 0-9 (NeoPixel range).
1717
Allows remapping light value to pixel position."""
18-
return int(value / 320 * 10)
18+
return round(value / 320 * 9)
1919

2020

2121
while True:
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""This example lights up the first NeoPixel red."""
2+
from adafruit_circuitplayground import cp
3+
4+
cp.pixels.brightness = 0.3
5+
6+
while True:
7+
cp.pixels[0] = (255, 0, 0)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""This example lights up all the NeoPixel LEDs red."""
2+
from adafruit_circuitplayground import cp
3+
4+
while True:
5+
cp.pixels.fill((50, 0, 0))

examples/circuitplayground_shake.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
from adafruit_circuitplayground import cp
33

44
while True:
5-
if cp.shake(shake_threshold=20):
5+
if cp.shake():
66
print("Shake detected!")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""This example flashes the little red LED when the Circuit Playground is shaken."""
2+
from adafruit_circuitplayground import cp
3+
4+
while True:
5+
if cp.shake(shake_threshold=20):
6+
print("Shake detected!")
7+
cp.red_led = True
8+
else:
9+
cp.red_led = False

examples/circuitplayground_tapdetect.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""This example prints to the serial console when the board is double-tapped."""
2+
import time
23
from adafruit_circuitplayground import cp
34

45
# Change to 1 for single-tap detection.
@@ -7,3 +8,4 @@
78
while True:
89
if cp.tapped:
910
print("Tapped!")
11+
time.sleep(0.05)

examples/circuitplayground_tapdetect_single_double.py

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@
2222
tap_count += 1
2323
print("Reached 2 double-taps!")
2424
print("Done.")
25+
while True:
26+
cp.red_led = True
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""This example prints to the serial console when you touch capacitive touch pad A1."""
2+
from adafruit_circuitplayground import cp
3+
4+
while True:
5+
if cp.touch_A1:
6+
print('Touched pad A1')

0 commit comments

Comments
 (0)