Skip to content

Commit fa4d41c

Browse files
authored
Merge branch 'master' into philb-branch
2 parents 6edeb64 + b36c2b6 commit fa4d41c

8 files changed

Lines changed: 119 additions & 14 deletions

File tree

Hallowing_Jump_Sound/jump-sound.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
"""
77

88
import time
9-
import pulseio
109
import audioio
1110
import busio
1211
import board
12+
import digitalio
1313
import touchio
14-
import adafruit_lis3dh
1514
import neopixel
1615

1716
def load_wav(name):
@@ -39,32 +38,56 @@ def play_wav(wav):
3938
JUMP_THRESHOLD = 4.0 # Higher number = triggers more easily
4039
IMAGEFILE = 'mario.bmp' # BMP image to display
4140

41+
IS_HALLOWING_M4 = False
42+
43+
# Perform a couple extra steps for the HalloWing M4
44+
try:
45+
if getattr(board, "CAP_PIN"):
46+
IS_HALLOWING_M4 = True
47+
# Create digitalio objects and pull low for HalloWing M4
48+
cap_pin = digitalio.DigitalInOut(board.CAP_PIN)
49+
cap_pin.direction = digitalio.Direction.OUTPUT
50+
cap_pin.value = False
51+
if getattr(board, "SPEAKER_ENABLE"):
52+
# Enable the Speaker
53+
speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
54+
speaker_enable.direction = digitalio.Direction.OUTPUT
55+
speaker_enable.value = True
56+
except AttributeError:
57+
pass
58+
4259
AUDIO = audioio.AudioOut(board.A0) # Speaker
43-
BACKLIGHT = pulseio.PWMOut(board.TFT_BACKLIGHT) # Display backlight
60+
61+
board.DISPLAY.auto_brightness = False
4462
TOUCH1 = touchio.TouchIn(board.A2) # Capacitive touch pads
4563
TOUCH2 = touchio.TouchIn(board.A3)
4664
TOUCH3 = touchio.TouchIn(board.A4)
4765
TOUCH4 = touchio.TouchIn(board.A5)
4866

4967
# Set up accelerometer on I2C bus, 4G range:
5068
I2C = busio.I2C(board.SCL, board.SDA)
51-
try:
52-
ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x18) # Production board
53-
except ValueError:
54-
ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x19) # Beta hardware
55-
ACCEL.range = adafruit_lis3dh.RANGE_4_G
69+
if IS_HALLOWING_M4:
70+
import adafruit_msa301
71+
ACCEL = adafruit_msa301.MSA301(I2C)
72+
else:
73+
import adafruit_lis3dh
74+
try:
75+
ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x18) # Production board
76+
except ValueError:
77+
ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x19) # Beta hardware
78+
ACCEL.range = adafruit_lis3dh.RANGE_4_G
5679

5780
try:
5881
import displayio
82+
board.DISPLAY.brightness = 0
5983
SCREEN = displayio.Group()
6084
board.DISPLAY.show(SCREEN)
6185
BITMAP = displayio.OnDiskBitmap(open(IMAGEFILE, 'rb'))
6286
SCREEN.append(
63-
displayio.Sprite(BITMAP,
64-
pixel_shader=displayio.ColorConverter(),
65-
position=(0, 0)))
66-
board.DISPLAY.wait_for_frame() # Wait for the image to load.
67-
BACKLIGHT.duty_cycle = 65535 # Turn on display backlight
87+
displayio.TileGrid(BITMAP,
88+
pixel_shader=displayio.ColorConverter(),
89+
x=0, y=0))
90+
board.DISPLAY.brightness = 1.0
6891
except (ImportError, NameError, AttributeError) as err:
6992
pass # Probably earlier CircuitPython; no displayio support
7093

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Shake Audio Lamp
2+
# for Adafruit Circuit Playground express
3+
# with CircuitPython
4+
import time
5+
import audioio
6+
import board
7+
8+
from adafruit_circuitplayground.express import cpx
9+
10+
# External Audio Stuff
11+
audio = audioio.AudioOut(board.A0) # Speaker
12+
wave_file = None
13+
14+
def play_wav(name, loop=False):
15+
"""
16+
Play a WAV file in the 'sounds' directory.
17+
:param name: partial file name string, complete name will be built around
18+
this, e.g. passing 'foo' will play file 'sounds/foo.wav'.
19+
:param loop: if True, sound will repeat indefinitely (until interrupted
20+
by another sound).
21+
"""
22+
global wave_file # pylint: disable=global-statement
23+
print("playing", name)
24+
if wave_file:
25+
wave_file.close()
26+
try:
27+
wave_file = open('sounds/' + name + '.wav', 'rb') # using wave files from sounds folder
28+
wave = audioio.WaveFile(wave_file)
29+
audio.play(wave, loop=loop)
30+
except OSError:
31+
pass # we'll just skip playing then
32+
33+
# flash neopixel effects
34+
def party_flash(duration):
35+
cpx.pixels.fill((255, 255, 255))
36+
cpx.pixels.show()
37+
time.sleep(duration)
38+
cpx.pixels.fill((255, 0, 0))
39+
cpx.pixels.show()
40+
time.sleep(duration)
41+
42+
def led_flash(duration):
43+
cpx.pixels.fill((255, 255, 255))
44+
cpx.pixels.show()
45+
time.sleep(duration)
46+
cpx.pixels.fill((0, 0, 0))
47+
cpx.pixels.show()
48+
time.sleep(duration)
49+
50+
# make a counter variable
51+
counter = 0
52+
53+
while True:
54+
# Listen for shakes
55+
if cpx.shake(shake_threshold=15): # adjust sensitivity - low number is more sensitive
56+
print("Shake detected!") # Let us know there was a shake
57+
counter = counter + 1 # Start a counter
58+
if counter == 2: # On second shake
59+
play_wav("awe-a") # play audio
60+
for _ in range(3): # loop x times
61+
party_flash(0.4) # neopixel flash
62+
elif counter == 3: # On third shake
63+
play_wav("awe-b")
64+
for _ in range(3): # loop x times
65+
party_flash(0.4) # neopixel flash
66+
elif counter == 4: # On fourth shake
67+
play_wav("awe-c")
68+
for _ in range(3): # loop x times
69+
party_flash(0.4) # neopixel flash
70+
elif counter == 5: # on fifth shake
71+
counter = 0 # Reset the counter back to zero
72+
play_wav("untz") #play audio
73+
for _ in range(3): # loop x times
74+
led_flash(.18) # faster pixel flash
75+
cpx.pixels.fill((255,255,255)) # solid pixel
76+
time.sleep(1) # light it for one second
77+
else: # On first shake
78+
play_wav("haha") # play audio
79+
cpx.pixels.fill((255,255,255)) # white color
80+
time.sleep(1) # for one second
81+
else: # When there's no shakyness to be had
82+
cpx.pixels.fill((0, 0, 0)) # keep pixels off when not shaking
99.1 KB
Binary file not shown.
112 KB
Binary file not shown.
108 KB
Binary file not shown.

LEGO_Head_CPX_Lamp/sounds/haha.wav

58.3 KB
Binary file not shown.

LEGO_Head_CPX_Lamp/sounds/untz.wav

97.6 KB
Binary file not shown.

pyportal_weather_station/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
PyPortal Weather Station
33
==============================================
4-
Turn your PyPortal into a weaterstation with
4+
Turn your PyPortal into a weatherstation with
55
Adafruit IO
66
77
Author: Brent Rubell for Adafruit Industries, 2019

0 commit comments

Comments
 (0)