Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
makermelissa committed Oct 11, 2023
2 parents 2bae131 + 89e3823 commit 96bc373
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Feather_ePaper_Quotes/adafruit_feather_quote/secrets.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT

#ifndef _SECRET_H THEN
#ifndef _SECRET_H
#define _SECRET_H

// define your WIFI SSID and password in this file
Expand Down
79 changes: 79 additions & 0 deletions HAL9000_RP2040_PropMaker/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# SPDX-FileCopyrightText: 2023 Phil Burgess for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
HAL 9000 demo project for Adafruit Prop Maker Feather RP2040 and "Massive
Arcade Button with LED - 100mm red." This simply monitors for button presses
and then randomly plays one WAV file from the CIRCUITPY filesystem.
No soldering required; using quick-connects, LED and button can be wired
to screw terminals on the Prop Maker Feather board.
NOTE: WAV FILES MUST BE 16-BIT. This will be fixed (allowing 8-bit WAVs if
desired) in CircuitPython 9.0.
"""

# pylint: disable=import-error
import os
import random
import time
import audiocore
import audiobusio
import board
import digitalio
import pwmio


# HARDWARE SETUP -----------------------------------------------------------

# LED+ is wired to "Neo" pin on screw terminal header, LED- to GND.
# The LED inside the button is NOT a NeoPixel, just a normal passive LED,
# but that's okay here -- the "Neo" pin can also function like a simple
# 5V digital output or PWM pin.
led = pwmio.PWMOut(board.EXTERNAL_NEOPIXELS)
led.duty_cycle = 65535 # LED ON by default

# Button is wired to GND and "Btn" on screw terminal header:
button = digitalio.DigitalInOut(board.EXTERNAL_BUTTON)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP

# Enable power to audio amp, etc.
external_power = digitalio.DigitalInOut(board.EXTERNAL_POWER)
external_power.direction = digitalio.Direction.OUTPUT
external_power.value = True

# I2S audio out
audio = audiobusio.I2SOut(board.I2S_BIT_CLOCK, board.I2S_WORD_SELECT, board.I2S_DATA)

# Find all Wave files in CIRCUITPY storage:
wavefiles = [
file
for file in os.listdir("/sounds/")
if (file.endswith(".wav") and not file.startswith("._"))
]
print("Audio files found:", wavefiles)

# FUNCTIONS ----------------------------------------------------------------


def play_file(filename):
"""Plays a WAV file in its entirety (function blocks until done)."""
print("Playing", filename)
with open(f"/sounds/{filename}", "rb") as file:
audio.play(audiocore.WaveFile(file))
# Randomly flicker the LED a bit while audio plays
while audio.playing:
led.duty_cycle = random.randint(5000, 30000)
time.sleep(0.1)
led.duty_cycle = 65535 # Back to full brightness


# MAIN LOOP ----------------------------------------------------------------


# Loop simply watches for a button press (button pin pulled to GND, thus
# False) and then plays a random WAV file. Because the WAV-playing function
# will take a few seconds, this doesn't even require button debouncing.
while True:
if button.value is False:
play_file(random.choice(wavefiles))
Binary file added HAL9000_RP2040_PropMaker/sounds/HAL.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/fault.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/goodbye.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/info.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/mission.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/moment.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/printing.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/puzzling.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/python.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/reload.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/repl.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/serious.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/silly.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/sorry.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/state.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/what.wav
Binary file not shown.
Binary file added HAL9000_RP2040_PropMaker/sounds/zero.wav
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, display, width, height, shader=None, bit_depth=16):
self._buffer_group[1].append(buffer1_sprite)

def show(self, swap=True):
self.display.show(self._buffer_group[self._active_buffer])
self.display.root_group = self._buffer_group[self._active_buffer]
if swap:
self.swap()

Expand Down

0 comments on commit 96bc373

Please sign in to comment.