Modify the python code to make the LED blink three times rapidly followed by a p
ID: 3802419 • Letter: M
Question
Modify the python code to make the LED blink three times rapidly followed by a pause of five
seconds, followed by four rapid blinks, another pause and repeating the whole thing again in a loop till
you terminate the python script.
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
def Blink():
for i in range(0,3):
print "blink #" + str(i+1)
GPIO.output(17,True)
time.sleep(1)
GPIO.output(17,False)
time.sleep(1)
print "done!!"
GPIO.cleanup()
Blink()
Explanation / Answer
Python script will be look like
for i in range(0,3):
print "blink #" + str(i+1)
GPIO.output(17,True)
time.sleep(1)
GPIO.output(17,False)
time.sleep(1)
for i in range(0,4):
print "blink #" + str(i+1)
GPIO.output(17,True)
time.sleep(1)
GPIO.output(17,False)
time.sleep(1)
print "done!!"
GPIO.cleanup()
Blink()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.