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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 3 deletions
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)
Lines changed: 15 additions & 0 deletions
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))
Lines changed: 15 additions & 0 deletions
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))
Lines changed: 12 additions & 0 deletions
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)
Lines changed: 14 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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:
Lines changed: 7 additions & 0 deletions
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)
Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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!")

0 commit comments

Comments
 (0)