Skip to content

Instantly share code, notes, and snippets.

@tangrs
Last active August 29, 2015 14:04
Show Gist options
  • Save tangrs/09e82102d1aaaa7bc87e to your computer and use it in GitHub Desktop.
Save tangrs/09e82102d1aaaa7bc87e to your computer and use it in GitHub Desktop.
Files used in The Success Box
import os, random, time
from pygame import mixer
def play(filename):
if filename == None:
return
mixer.init()
print "Playing", filename
mixer.music.load(filename)
mixer.music.play()
def stop():
mixer.music.stop()
mixer.quit()
def pick_track(dir):
files = []
for r, d, f in os.walk(dir):
for fname in f:
if fname.lower().endswith(".mp3") and not fname.startswith("."):
path = os.path.join(r, fname)
files.append(path)
if (len(files) == 0):
return None
return random.choice(files)
def gpio_get():
with open("/sys/class/gpio/gpio1/value") as f:
return (f.read(1) == '1')
def gpio_wait(until = False):
# Should use poll
while gpio_get() != until:
time.sleep(0.1)
while True:
try:
# Wait for button press (i.e. go high, circuit open)
gpio_wait(True)
track = pick_track("/media")
play(track)
# Wait for button to unpress
gpio_wait(False)
stop()
except KeyboardInterrupt:
raise
except:
# Steamroller dis shit
pass
use <rpi.scad> // The RPi SCAD model can be found at https://github.com/TomHodson/Raspberry-Pi-OpenSCAD-Model
module box() {
wall_width = 3;
dim = [88, 85, 80];
difference() {
cube(size=dim + [2*wall_width, 2*wall_width, wall_width]);
translate(v=[wall_width, wall_width, -1])
cube(size=dim + [0,0,1]);
translate(v=[-10,2.25,34])
cube(size=[35, 4, 27]);
translate(v=[-10,4,63])
cube(size=[17.3, 10, 13.3]);
translate(v=[80,6.5,37.5])
cube(size=[17.3,18,16]);
translate(v=[44+2.25, 42.5+2.25, 70])
cylinder(d=24, h=20);
translate(v=[2.25,0,0]) {
translate(v=[44, 95, 40])
rotate(a=[90,0,0])
cylinder(d=55, h=20);
translate(v=[11.8, 95, 40])
rotate(a=[90,0,0])
cylinder(d=5, h=20);
translate(v=[60, 95, 68])
rotate(a=[90,0,0])
cylinder(d=5, h=20);
translate(v=[60, 95, 12])
rotate(a=[90,0,0])
cylinder(d=5, h=20);
}
}
}
rotate(a=[180,0,0]) {
//projection(cut = true)
//translate(v=[0,0,-89])
box();
translate(v=[4,6,77])
rotate(a=[-90,0,0])
rpi();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment