raspberry pi python make led blink code example
Example 1: blinking an led with raspberry pi
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
while True:
GPIO.output(18, True)
time.sleep(1)
GPIO.output(18, False)
time.sleep(1)
Example 2: how to make 2 lights blink with the GPIO pins with python
while True:
import RPi.GPIO as GPIO
import time
x = (0.3)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.OUT)
GPIO.setup(5, GPIO.OUT)
GPIO.output(3, GPIO.LOW)
GPIO.output(5, GPIO.HIGH)
time.sleep(x)
GPIO.output(3,GPIO.HIGH)
GPIO.output(5, GPIO.LOW)
time.sleep(x)
GPIO.cleanup()