Skip to content

Commit b863076

Browse files
committed
Adding PyLeap example code and files.
1 parent c32ccda commit b863076

11 files changed

Lines changed: 216 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
Circuit Playground Bluefruit NeoPixel Light Meter.
7+
8+
Shine a light on the front of the Circuit Playground Bluefruit to see the number of NeoPixels lit
9+
up increase. Cover the front of the CPB to see the number decrease.
10+
"""
11+
from adafruit_circuitplayground import cp
12+
13+
# Choose a color. Defaults to cyan. This is an RGB value, where (r, g, b) represents red, green,
14+
# and blue. Each value has a range of 0-255, where 0 is off and 255 is max intensity. You can
15+
# update these values to change the colors. For example, (0, 255, 0) would be max green. You can
16+
# combine numbers within the range to make other colors such as (255, 0, 180) being pink.
17+
# Try it out!
18+
color_value = (0, 255, 255)
19+
20+
cp.pixels.auto_write = False
21+
cp.pixels.brightness = 0.3
22+
23+
24+
def scale_range(value):
25+
"""Scale a value from 0-320 (light range) to 0-9 (NeoPixel range).
26+
Allows remapping light value to pixel position."""
27+
return round(value / 320 * 9)
28+
29+
30+
while True:
31+
peak = scale_range(cp.light)
32+
33+
for i in range(10):
34+
if i <= peak:
35+
cp.pixels[i] = color_value
36+
else:
37+
cp.pixels[i] = (0, 0, 0)
38+
cp.pixels.show()

PyLeap_Bluefruit_MP3/beats.mp3

13.6 KB
Binary file not shown.

PyLeap_Bluefruit_MP3/code.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
Circuit Playground Bluefruit MP3 Playback
7+
8+
Press each button on the Circuit Playground Bluefruit to play a different MP3.
9+
"""
10+
from adafruit_circuitplayground import cp
11+
12+
while True:
13+
if cp.button_a:
14+
cp.play_mp3("happy.mp3")
15+
if cp.button_b:
16+
cp.play_mp3("beats.mp3")

PyLeap_Bluefruit_MP3/happy.mp3

24.1 KB
Binary file not shown.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
Circuit Playground Bluefruit NeoPixel Sound Meter
7+
8+
Talk or make noise close to your Circuit Playground Bluefruit to see the NeoPixels light up.
9+
"""
10+
from adafruit_circuitplayground import cp
11+
12+
# Choose a color. Defaults to red. This is an RGB value, where (r, g, b) represents red, green,
13+
# and blue. Each value has a range of 0-255, where 0 is off and 255 is max intensity. You can
14+
# update these values to change the colors. For example, (0, 255, 0) would be max green. You can
15+
# combine numbers within the range to make other colors such as (255, 0, 180) being pink.
16+
# Try it out!
17+
color_value = (255, 0, 0)
18+
19+
# This is the sound level needed to light up all 10 NeoPixels. If all the LEDs are lighting up too
20+
# easily, increase this value to make it more difficult to reach the max. If you are only able to
21+
# light up a few LEDs, decrease this value to make it easier to reach the max. Full possible sound
22+
# range is 0 - 65535.
23+
sound_max = 1500
24+
25+
cp.pixels.auto_write = False
26+
cp.pixels.brightness = 0.3
27+
28+
29+
def scale_range(value):
30+
"""Scale a value from 0-sound_max (chosen sound range) to 0-9 (NeoPixel range).
31+
Allows remapping sound value to pixel position.
32+
Full sound range is 0 - 65535. sound_max should be chosen based on testing."""
33+
return round(value / sound_max * 9)
34+
35+
36+
while True:
37+
peak = scale_range(cp.sound_level)
38+
39+
for pixel in range(10):
40+
if pixel <= peak:
41+
cp.pixels[pixel] = color_value
42+
else:
43+
cp.pixels[pixel] = (0, 0, 0) # Off
44+
cp.pixels.show()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
Circuit Playground Bluefruit Light-Up Tone Piano
7+
8+
Touch the each of the touchpads around the outside of the board to play a tone for each pad.
9+
Touch A6 and TX at the same time to play the final tone in the octave. A0 is not a touchpad.
10+
"""
11+
12+
from adafruit_circuitplayground import cp
13+
14+
cp.pixels.brightness = 0.3
15+
16+
while True:
17+
if cp.touch_A1:
18+
cp.pixels.fill((255, 0, 0))
19+
cp.start_tone(262)
20+
elif cp.touch_A2:
21+
cp.pixels.fill((210, 45, 0))
22+
cp.start_tone(294)
23+
elif cp.touch_A3:
24+
cp.pixels.fill((155, 155, 0))
25+
cp.start_tone(330)
26+
elif cp.touch_A4:
27+
cp.pixels.fill((0, 255, 0))
28+
cp.start_tone(349)
29+
elif cp.touch_A5:
30+
cp.pixels.fill((0, 255, 255))
31+
cp.start_tone(392)
32+
elif cp.touch_A6 and not cp.touch_A7:
33+
cp.pixels.fill((0, 0, 255))
34+
cp.start_tone(440)
35+
elif cp.touch_A7 and not cp.touch_A6:
36+
cp.pixels.fill((100, 0, 255))
37+
cp.start_tone(494)
38+
elif cp.touch_A6 and cp.touch_A7:
39+
cp.pixels.fill((255, 0, 255))
40+
cp.start_tone(523)
41+
else:
42+
cp.pixels.fill((0, 0, 0))
43+
cp.stop_tone()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
Circuit Playground Bluefruit Capacitive Touch Rainbow
7+
8+
Touch the each of the touchpads around the outside of the board to light up the pixels a different
9+
color for each pad touched.
10+
"""
11+
from adafruit_circuitplayground import cp
12+
13+
cp.pixels.brightness = 0.3
14+
15+
while True:
16+
if cp.touch_A1:
17+
cp.pixels.fill((255, 0, 0))
18+
if cp.touch_A2:
19+
cp.pixels.fill((210, 45, 0))
20+
if cp.touch_A3:
21+
cp.pixels.fill((155, 100, 0))
22+
if cp.touch_A4:
23+
cp.pixels.fill((0, 255, 0))
24+
if cp.touch_A5:
25+
cp.pixels.fill((0, 135, 125))
26+
if cp.touch_A6:
27+
cp.pixels.fill((0, 0, 255))
28+
if cp.touch_TX:
29+
cp.pixels.fill((100, 0, 155))

PyLeap_Bluefruit_WAV/code.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
Circuit Playground Bluefruit WAV Playback
7+
8+
Press each button on the Circuit Playground Bluefruit to play a different WAV.
9+
"""
10+
from adafruit_circuitplayground import cp
11+
12+
while True:
13+
if cp.button_a:
14+
cp.play_file("dip.wav")
15+
if cp.button_b:
16+
cp.play_file("rise.wav")

PyLeap_Bluefruit_WAV/dip.wav

25.9 KB
Binary file not shown.

PyLeap_Bluefruit_WAV/rise.wav

25.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)