Merge pull request #1920 from kattni/pyleap-examples
Adding PyLeap example code and files.
This commit is contained in:
commit
f610abc293
11 changed files with 216 additions and 0 deletions
38
PyLeap_Bluefruit_Light_Meter/code.py
Normal file
38
PyLeap_Bluefruit_Light_Meter/code.py
Normal file
|
|
@ -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()
|
||||
BIN
PyLeap_Bluefruit_MP3/beats.mp3
Executable file
BIN
PyLeap_Bluefruit_MP3/beats.mp3
Executable file
Binary file not shown.
16
PyLeap_Bluefruit_MP3/code.py
Normal file
16
PyLeap_Bluefruit_MP3/code.py
Normal file
|
|
@ -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")
|
||||
BIN
PyLeap_Bluefruit_MP3/happy.mp3
Executable file
BIN
PyLeap_Bluefruit_MP3/happy.mp3
Executable file
Binary file not shown.
44
PyLeap_Bluefruit_Sound_Meter/code.py
Normal file
44
PyLeap_Bluefruit_Sound_Meter/code.py
Normal file
|
|
@ -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
PyLeap_Bluefruit_Tone_Piano/code.py
Normal file
43
PyLeap_Bluefruit_Tone_Piano/code.py
Normal file
|
|
@ -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
PyLeap_Bluefruit_Touch_NeoPIxel_Rainbow/code.py
Normal file
29
PyLeap_Bluefruit_Touch_NeoPIxel_Rainbow/code.py
Normal file
|
|
@ -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
PyLeap_Bluefruit_WAV/code.py
Normal file
16
PyLeap_Bluefruit_WAV/code.py
Normal file
|
|
@ -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")
|
||||
BIN
PyLeap_Bluefruit_WAV/dip.wav
Normal file
BIN
PyLeap_Bluefruit_WAV/dip.wav
Normal file
Binary file not shown.
BIN
PyLeap_Bluefruit_WAV/rise.wav
Normal file
BIN
PyLeap_Bluefruit_WAV/rise.wav
Normal file
Binary file not shown.
30
PyLeap_Button_Half_NeoPixel_Control/code.py
Normal file
30
PyLeap_Button_Half_NeoPixel_Control/code.py
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue