Skip to content

Instantly share code, notes, and snippets.

@saragibby
Created December 19, 2018 05:15
Show Gist options
  • Save saragibby/04d090aab7ed26e7be919dfd495b2a77 to your computer and use it in GitHub Desktop.
Save saragibby/04d090aab7ed26e7be919dfd495b2a77 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
redLightsPin = 15
greenLightsPin = 11
yellowLightsPin = 13
purpleLightsPin = 7
allPins = [redLightsPin, yellowLightsPin, greenLightsPin, purpleLightsPin]
def setup():
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
for pin in allPins:
GPIO.setup(pin, GPIO.OUT) # Set all pins' mode is output
GPIO.output(pin, GPIO.HIGH) # Set all pins to high(+3.3V) to off led
def playJingleBells():
for x in range(2):
print 'Jingle bells'
flashLights(redLightsPin)
time.sleep(0.2) # additional sleep for longer pause in song
print 'Jingle bells'
flashLights(greenLightsPin)
time.sleep(0.2) # additional sleep for longer pause in song
print 'jingle all the way'
turnOn(redLightsPin)
time.sleep(0.2)
turnOn(greenLightsPin)
time.sleep(0.2)
turnOn(yellowLightsPin)
time.sleep(0.2)
turnOn(greenLightsPin)
time.sleep(0.2)
turnOn(redLightsPin, 0.8)
time.sleep(0.4)
print 'oh what fun'
flashLights(yellowLightsPin)
time.sleep(0.2) # additional sleep for longer pause in song
print 'it is to ride in a one-horse open sleigh'
turnOn(redLightsPin)
time.sleep(0.2)
turnOn(greenLightsPin)
time.sleep(0.2)
turnOn(yellowLightsPin)
time.sleep(0.2)
turnOn(greenLightsPin)
time.sleep(0.2)
turnOn(redLightsPin)
time.sleep(0.2)
turnOn(yellowLightsPin)
time.sleep(0.2)
turnOn(redLightsPin)
time.sleep(0.2)
turnOn(greenLightsPin)
time.sleep(0.2)
turnOn(yellowLightsPin)
time.sleep(0.2)
turnOn(greenLightsPin)
time.sleep(0.4)
if x == 0: # only run first trip through loop
print 'hey'
turnOn(purpleLightsPin, 0.9)
flashLights(purpleLightsPin, 5, 0.05, 0.1)
def turnOn(pinNumber, stayLitFor=0.3):
GPIO.output(pinNumber, GPIO.LOW)
time.sleep(stayLitFor)
GPIO.output(pinNumber, GPIO.HIGH)
def flashLights(
pinNumber,
numberOfFlashes=3,
amountToSleep=0.2,
stayLitFor=0.3,
):
for x in range(numberOfFlashes):
turnOn(pinNumber, stayLitFor)
time.sleep(amountToSleep)
def destroy():
for pin in allPins:
GPIO.output(pin, GPIO.HIGH) # turn off all leds
GPIO.cleanup() # Release resource
if __name__ == '__main__': # Program start from here
setup()
try:
playJingleBells()
GPIO.cleanup()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
destroy()
@ROBOMASTER-S1
Copy link

I have lots of Raspberry Pi 4 programs I had done, using Python that you might like. I also explain the
materials you will need to hook things up to the Raspberry Pi, such as Resistors, how many wires needed.
LCD displays and anything else I might use within a Raspberry Pi 4 program. I have a lot of stuff to do
with the Raspberry Pi 4. However at the moment, I only deal with Python programming. I'm almost a
complete computer science research laboratory machine on two legs. I also deal with the Robomaster S1
robot from dji. I also have Cozmo robot programs, but only two or three are my own. He broke and I
couldn't go any farther with that ripoff machine. I also have tons of Python programming examples of
straight up Python programming. If you are using Python and want to learn faster without watching
or searching around. You can always check out my Python files. I'm pretty sure I will have something you
might need down the road and I make it all free for everyone, who seeks what I love to do.

Thank you for your time.

Joe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment