Skip to content

Instantly share code, notes, and snippets.

@frangucc
Created June 15, 2016 20:20
Show Gist options
  • Save frangucc/4804e1fb3a6f6f541ed35c1200a13217 to your computer and use it in GitHub Desktop.
Save frangucc/4804e1fb3a6f6f541ed35c1200a13217 to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO ## Import GPIO Library
import time ## Import 'time' library. Allows us to use 'sleep'
GPIO.setmode(GPIO.BOARD) ## Use BOARD pin numbering
GPIO.setup(7, GPIO.OUT) ## Setup GPIO pin 7 to OUT
## Define function named Blink()
def Blink(numTimes, speed):
for i in range(0,numTimes): ## Run loop numTimes
print "Iteration " + str(i+1) ##Print current loop
GPIO.output(7, True) ## Turn on GPIO pin 7
time.sleep(speed) ## Wait
GPIO.output(7, False) ## Switch off GPIO pin 7
time.sleep(speed) ## Wait
print "Done" ## When loop is complete, print "Done"
GPIO.cleanup()
## Prompt user for input
iterations = raw_input("Enter the total number of times to blink: ")
speed = raw_input("Enter the length of each blink in seconds: ")
## Start Blink() function. Convert user input from strings to numeric data types and pass to Blink() as parameters
Blink(int(iterations),float(speed))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment