-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathledblink.py
executable file
·24 lines (19 loc) · 962 Bytes
/
ledblink.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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(22, 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(22, True) ## Turn on GPIO pin 7
time.sleep(speed) ## Wait
GPIO.output(22, 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))