Skip to content

Adding PyLeap example code and files. #1920

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 1 commit into from
Nov 11, 2021
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
38 changes: 38 additions & 0 deletions PyLeap_Bluefruit_Light_Meter/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
Circuit Playground Bluefruit NeoPixel Light Meter.

Shine a light on the front of the Circuit Playground Bluefruit to see the number of NeoPixels lit
up increase. Cover the front of the CPB to see the number decrease.
"""
from adafruit_circuitplayground import cp

# Choose a color. Defaults to cyan. This is an RGB value, where (r, g, b) represents red, green,
# and blue. Each value has a range of 0-255, where 0 is off and 255 is max intensity. You can
# update these values to change the colors. For example, (0, 255, 0) would be max green. You can
# combine numbers within the range to make other colors such as (255, 0, 180) being pink.
# Try it out!
color_value = (0, 255, 255)

cp.pixels.auto_write = False
cp.pixels.brightness = 0.3


def scale_range(value):
"""Scale a value from 0-320 (light range) to 0-9 (NeoPixel range).
Allows remapping light value to pixel position."""
return round(value / 320 * 9)


while True:
peak = scale_range(cp.light)

for i in range(10):
if i <= peak:
cp.pixels[i] = color_value
else:
cp.pixels[i] = (0, 0, 0)
cp.pixels.show()
Binary file added PyLeap_Bluefruit_MP3/beats.mp3
Binary file not shown.
16 changes: 16 additions & 0 deletions PyLeap_Bluefruit_MP3/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
Circuit Playground Bluefruit MP3 Playback

Press each button on the Circuit Playground Bluefruit to play a different MP3.
"""
from adafruit_circuitplayground import cp

while True:
if cp.button_a:
cp.play_mp3("happy.mp3")
if cp.button_b:
cp.play_mp3("beats.mp3")
Binary file added PyLeap_Bluefruit_MP3/happy.mp3
Binary file not shown.
44 changes: 44 additions & 0 deletions PyLeap_Bluefruit_Sound_Meter/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
Circuit Playground Bluefruit NeoPixel Sound Meter

Talk or make noise close to your Circuit Playground Bluefruit to see the NeoPixels light up.
"""
from adafruit_circuitplayground import cp

# Choose a color. Defaults to red. This is an RGB value, where (r, g, b) represents red, green,
# and blue. Each value has a range of 0-255, where 0 is off and 255 is max intensity. You can
# update these values to change the colors. For example, (0, 255, 0) would be max green. You can
# combine numbers within the range to make other colors such as (255, 0, 180) being pink.
# Try it out!
color_value = (255, 0, 0)

# This is the sound level needed to light up all 10 NeoPixels. If all the LEDs are lighting up too
# easily, increase this value to make it more difficult to reach the max. If you are only able to
# light up a few LEDs, decrease this value to make it easier to reach the max. Full possible sound
# range is 0 - 65535.
sound_max = 1500

cp.pixels.auto_write = False
cp.pixels.brightness = 0.3


def scale_range(value):
"""Scale a value from 0-sound_max (chosen sound range) to 0-9 (NeoPixel range).
Allows remapping sound value to pixel position.
Full sound range is 0 - 65535. sound_max should be chosen based on testing."""
return round(value / sound_max * 9)


while True:
peak = scale_range(cp.sound_level)

for pixel in range(10):
if pixel <= peak:
cp.pixels[pixel] = color_value
else:
cp.pixels[pixel] = (0, 0, 0) # Off
cp.pixels.show()
43 changes: 43 additions & 0 deletions PyLeap_Bluefruit_Tone_Piano/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
Circuit Playground Bluefruit Light-Up Tone Piano

Touch the each of the touchpads around the outside of the board to play a tone for each pad.
Touch A6 and TX at the same time to play the final tone in the octave. A0 is not a touchpad.
"""

from adafruit_circuitplayground import cp

cp.pixels.brightness = 0.3

while True:
if cp.touch_A1:
cp.pixels.fill((255, 0, 0))
cp.start_tone(262)
elif cp.touch_A2:
cp.pixels.fill((210, 45, 0))
cp.start_tone(294)
elif cp.touch_A3:
cp.pixels.fill((155, 155, 0))
cp.start_tone(330)
elif cp.touch_A4:
cp.pixels.fill((0, 255, 0))
cp.start_tone(349)
elif cp.touch_A5:
cp.pixels.fill((0, 255, 255))
cp.start_tone(392)
elif cp.touch_A6 and not cp.touch_A7:
cp.pixels.fill((0, 0, 255))
cp.start_tone(440)
elif cp.touch_A7 and not cp.touch_A6:
cp.pixels.fill((100, 0, 255))
cp.start_tone(494)
elif cp.touch_A6 and cp.touch_A7:
cp.pixels.fill((255, 0, 255))
cp.start_tone(523)
else:
cp.pixels.fill((0, 0, 0))
cp.stop_tone()
29 changes: 29 additions & 0 deletions PyLeap_Bluefruit_Touch_NeoPIxel_Rainbow/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
Circuit Playground Bluefruit Capacitive Touch Rainbow

Touch the each of the touchpads around the outside of the board to light up the pixels a different
color for each pad touched.
"""
from adafruit_circuitplayground import cp

cp.pixels.brightness = 0.3

while True:
if cp.touch_A1:
cp.pixels.fill((255, 0, 0))
if cp.touch_A2:
cp.pixels.fill((210, 45, 0))
if cp.touch_A3:
cp.pixels.fill((155, 100, 0))
if cp.touch_A4:
cp.pixels.fill((0, 255, 0))
if cp.touch_A5:
cp.pixels.fill((0, 135, 125))
if cp.touch_A6:
cp.pixels.fill((0, 0, 255))
if cp.touch_TX:
cp.pixels.fill((100, 0, 155))
16 changes: 16 additions & 0 deletions PyLeap_Bluefruit_WAV/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
Circuit Playground Bluefruit WAV Playback

Press each button on the Circuit Playground Bluefruit to play a different WAV.
"""
from adafruit_circuitplayground import cp

while True:
if cp.button_a:
cp.play_file("dip.wav")
if cp.button_b:
cp.play_file("rise.wav")
Binary file added PyLeap_Bluefruit_WAV/dip.wav
Binary file not shown.
Binary file added PyLeap_Bluefruit_WAV/rise.wav
Binary file not shown.
30 changes: 30 additions & 0 deletions PyLeap_Button_Half_NeoPixel_Control/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""Circuit Playground Bluefruit NeoPixel Button Control

Press button A to light up half the NeoPixels and button B to light up the other half.
"""
from adafruit_circuitplayground import cp

# Choose colors. Defaults to red for button A and green for button B. These are RGB values, where
# (r, g, b) represents red, green, and blue. Each value has a range of 0-255, where 0 is off and
# 255 is max intensity. You can update these values to change the colors. For example, (0, 255, 0)
# would be max green. You can combine numbers within the range to make other colors such as
# (255, 0, 180) being pink. Try it out!
color_value_a = (255, 0, 0)
color_value_b = (0, 255, 0)

cp.pixels.brightness = 0.3

while True:
if cp.button_a:
cp.pixels[0:5] = [color_value_a] * 5
else:
cp.pixels[0:5] = [(0, 0, 0)] * 5

if cp.button_b:
cp.pixels[5:10] = [color_value_b] * 5
else:
cp.pixels[5:10] = [(0, 0, 0)] * 5