Created
October 1, 2015 06:10
-
-
Save KaiCode2/97be5d5c7a1cce223742 to your computer and use it in GitHub Desktop.
My fun little script that I built for an introduction to programming on the raspberry pi with a breadboard. Hook up a blue and red LED and connect them to the translating channels in the script and watch your breadboard turn into a cop car!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Made by Kai Aldag on September 30, 2015 | |
# Imports | |
import RPi.GPIO as GPIO | |
import sys | |
import time | |
# Setup | |
GPIO.setmode(GPIO.BOARD) | |
blue_chan = 11 # Channel specific to my project, change these values | |
red_chan = 13 # same as above | |
GPIO.setup([blue_chan, red_chan], GPIO.OUT) | |
GPIO.output([blue_chan, red_chan], 0) | |
# Application | |
should_run = True | |
current = "Blue" | |
try: | |
interval = int(sys.argv[1]) | |
except IndexError: | |
interval = 0.5 | |
except ValueError: | |
interval = 0.5 | |
while should_run: | |
if current == "Blue": | |
GPIO.output(blue_chan, 1) | |
GPIO.output(red_chan, 0) | |
current = "Red" | |
else: | |
GPIO.output(red_chan, 1) | |
GPIO.output(blue_chan, 0) | |
current = "Blue" | |
time.sleep(interval) | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment