1.3k
In our previous example we flashed an LED on, here are another couple of examples
This will flash the led on and off
[codesyntax lang=”python”]
import RPi.GPIO as GPIO import time GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) ## Use board pin numbering GPIO.setup(7, GPIO.OUT) ## Setup GPIO Pin 7 to OUT state = True # endless loop while True: GPIO.output(7,True)## Turn on GPIO pin 7 time.sleep(1) ## 1 second GPIO.output(7,False)## Turn off GPIO pin 7 time.sleep(1)## 1 second
[/codesyntax]
And no we will flash the LED 3 times
[codesyntax lang=”python”]
import RPi.GPIO as GPIO ## Import GPIO library import time GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) ## Use board pin numbering GPIO.setup(7, GPIO.OUT) ## Setup GPIO Pin 7 to OUT for i in range(0,3):## Run loop 3 times GPIO.output(7,True)## Switch on pin 7 time.sleep(1)## Wait 1 second GPIO.output(7,False)## Switch off pin 7 time.sleep(1)## Wait 1 second
[/codesyntax]