Skip to content

Commit e056631

Browse files
committed
Update examples.
1 parent fc2c9d6 commit e056631

14 files changed

+94
-5
lines changed
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
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."""
1818
return int(value / 320 * 10)
1919

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!")
Lines changed: 9 additions & 0 deletions
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

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

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