├── sfx └── .gitignore ├── .gitignore ├── assets └── circuit.jpg ├── speakerphat.py ├── README.md └── awkbox.py /sfx/.gitignore: -------------------------------------------------------------------------------- 1 | *.mp3 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | deploy.sh 2 | *.DS_Store 3 | env/ 4 | *.pyc 5 | -------------------------------------------------------------------------------- /assets/circuit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orangespaceman/awkbox/master/assets/circuit.jpg -------------------------------------------------------------------------------- /speakerphat.py: -------------------------------------------------------------------------------- 1 | # taken from: 2 | # https://github.com/pimoroni/speaker-phat/blob/master/python/speakerphat.py 3 | 4 | import atexit 5 | from sys import exit 6 | 7 | try: 8 | import sn3218 9 | except ImportError: 10 | error = """This library requires the sn3218 module. 11 | Install with: sudo pip install sn3218""" 12 | exit(error) 13 | 14 | 15 | stupid_led_mappings = [0, 1, 2, 4, 6, 8, 10, 12, 14, 16] 16 | 17 | led_values = [0 for x in range(18)] 18 | enable_leds = 0 19 | 20 | WIDTH = 10 21 | HEIGHT = 1 22 | 23 | for x in stupid_led_mappings: 24 | enable_leds |= 1 << x 25 | 26 | sn3218.enable_leds(enable_leds) 27 | sn3218.enable() 28 | 29 | 30 | def set_led(index, value): 31 | led_values[stupid_led_mappings[index]] = value 32 | 33 | 34 | def show(): 35 | sn3218.output(led_values) 36 | 37 | 38 | def clear(): 39 | global led_values 40 | led_values = [0 for x in range(18)] 41 | show() 42 | 43 | 44 | atexit.register(clear) 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Awkbox 2 | 3 | A Raspberry Pi-powered soundboard that plays stupid sound clips when shaken. 4 | 5 | ## Construction 6 | 7 | This uses a Raspberry Pi Zero and a Speaker pHAT. 8 | 9 | * Set up the pHAT: https://learn.pimoroni.com/tutorial/sandyj/assembling-speaker-phat 10 | 11 | * Add a sensor; this uses a tilt switch but this could easily be replaced with a button switch or similar. 12 | 13 | Wires were wrapped around the header pins 5V, Ground and input 23 for the switch. 14 | 15 | ![Pi](assets/circuit.jpg) 16 | 17 | ## Code 18 | 19 | * Install the software by following these instructions: https://github.com/pimoroni/speaker-phat 20 | 21 | * Check this repo out onto the pi 22 | 23 | * Set up the script to run on boot by editing the following file: 24 | 25 | ``` 26 | sudo nano /etc/rc.local 27 | ``` 28 | 29 | Add to the bottom of the file: 30 | 31 | ``` 32 | # awkbox 33 | python /home/pi/awkbox/awkbox.py & 34 | ``` 35 | 36 | ## Misc 37 | 38 | Add .mp3 files to the `sfx` directory. 39 | 40 | To adjust the volume control: 41 | 42 | ``` 43 | $ alsameter 44 | ``` 45 | -------------------------------------------------------------------------------- /awkbox.py: -------------------------------------------------------------------------------- 1 | import os 2 | import random 3 | import time 4 | import RPi.GPIO as GPIO 5 | import speakerphat 6 | import pygame 7 | 8 | # tilt 9 | tiltswitchPin = 23 10 | tiltState = 1 # 0 or 1, depending on whether the tilt switch is active 11 | lastTiltState = 1 12 | 13 | # play 14 | is_playing = False 15 | pygame.init() 16 | pygame.mixer.init() 17 | sfx_path = "/home/pi/awkbox/sfx" 18 | 19 | # lights 20 | active_led = 0 21 | led_direction = -1 22 | led_count = 9 23 | led_brightness = 255 24 | 25 | # GPIO 26 | GPIO.setmode(GPIO.BCM) 27 | GPIO.setup(tiltswitchPin, GPIO.IN) 28 | 29 | while True: 30 | # get state 31 | is_playing = pygame.mixer.music.get_busy() 32 | tiltState = GPIO.input(tiltswitchPin) 33 | 34 | # play 35 | if tiltState is not 1 and lastTiltState is 1 and is_playing is not True: 36 | sfx = random.choice(os.listdir(sfx_path)) 37 | pygame.mixer.music.load("%s/%s" % (sfx_path, sfx)) 38 | pygame.mixer.music.play() 39 | print sfx 40 | 41 | # lights 42 | if is_playing: 43 | if active_led == led_count or active_led == 0: 44 | led_direction = -led_direction 45 | active_led += led_direction 46 | led_brightness = 255 47 | else: 48 | active_led = 0 49 | led_direction = -1 50 | led_brightness = 0 if led_brightness == 255 else 255 51 | 52 | speakerphat.clear() 53 | speakerphat.set_led(active_led, led_brightness) 54 | speakerphat.show() 55 | 56 | lastTiltState = tiltState 57 | time.sleep(0.5) 58 | --------------------------------------------------------------------------------