Skip to content

Instantly share code, notes, and snippets.

@adamdaigian
Created August 5, 2014 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamdaigian/611372bf6d29e824df9d to your computer and use it in GitHub Desktop.
Save adamdaigian/611372bf6d29e824df9d to your computer and use it in GitHub Desktop.
#!/usr/bin/python -u
import time
print """ _
,' '.
/ \\
^ | _ | ^
| || / \\ || |
| |||.-.||| |
| ||| ||| |
| ||| ||| |
| ||| ||| |
| ||| ||| |
| ,' '. |
,'__ __`.
/____ | ____\\
/_\\ |_|_| /_\\
"""
import RPi.GPIO as GPIO
import time
import pygame.mixer
UP_STEPS = {{ STEPS }}
DOWN_STEPS = {{ STEPS }}
GPIO.setmode(GPIO.BCM)
enable_pin = 18
coil_A_1_pin = 4
coil_A_2_pin = 17
coil_B_1_pin = 23
coil_B_2_pin = 24
coil_led = 25
GPIO.setup(enable_pin, GPIO.OUT)
GPIO.setup(coil_A_1_pin, GPIO.OUT)
GPIO.setup(coil_A_2_pin, GPIO.OUT)
GPIO.setup(coil_B_1_pin, GPIO.OUT)
GPIO.setup(coil_B_2_pin, GPIO.OUT)
GPIO.setup(coil_led, GPIO.OUT)
GPIO.output(enable_pin, 1)
def blink(duration, frequency):
GPIO.output(coil_led, 1)
time.sleep(secs/2)
GPIO.output(coil_led, 0)
time.sleep(secs/2)
def backwards(steps):
for i in range(0, steps / 4):
setStep(1, 0, 1, 0)
setStep(0, 1, 1, 0)
setStep(0, 1, 0, 1)
setStep(1, 0, 0, 1)
def forwards(steps):
for i in range(0, steps / 4):
setStep(1, 0, 0, 1)
setStep(0, 1, 0, 1)
setStep(0, 1, 1, 0)
setStep(1, 0, 1, 0)
def setStep(w1, w2, w3, w4, delay=0.007):
time.sleep(delay)
GPIO.output(coil_A_1_pin, w1)
GPIO.output(coil_A_2_pin, w2)
GPIO.output(coil_B_1_pin, w3)
GPIO.output(coil_B_2_pin, w4)
pygame.mixer.init(48000,-16, 1, 1024)
countdown = pygame.mixer.Sound("launch.wav")
blast = pygame.mixer.Sound("BlastOff.wav")
land = pygame.mixer.Sound("Journey.wav")
channelA = pygame.mixer.Channel(1)
channelA.play(countdown)
# blink(11.0, 0.5)
time.sleep(11)
channelA.play(blast)
backwards(DOWN_STEPS)
channelA.fadeout(5000)
time.sleep(10)
channelA.set_volume(1.0)
channelA.play(land)
forwards(UP_STEPS)
GPIO.cleanup()
time.sleep(10)
channelA.fadeout(5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment