Table of Contents

controlling LED's with GPIO

turn on 1 LED

led-on.py

import RPi.GPIO as GPIO
 
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17,GPIO.OUT)
 
GPIO.output(17,GPIO.HIGH)

turn off 1 LED

led-off.py

import RPi.GPIO as GPIO
 
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17,GPIO.OUT)
 
GPIO.output(17,GPIO.LOW)

1 blinking LED

led-blink.py

import RPi.GPIO as GPIO
import time
 
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17,GPIO.OUT)
 
while True:
        GPIO.output(17,GPIO.HIGH)
        time.sleep(1)
        GPIO.output(17,GPIO.LOW)
        time.sleep(1)

3 blinking LED's

led-blink-3.py

import RPi.GPIO as GPIO
import time
 
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17,GPIO.OUT)
GPIO.setup(27,GPIO.OUT)
GPIO.setup(22,GPIO.OUT)
 
while True:
        GPIO.output(17,GPIO.HIGH)
        time.sleep(.2)
        GPIO.output(17,GPIO.LOW)
        GPIO.output(27,GPIO.HIGH)
        time.sleep(.2)
        GPIO.output(27,GPIO.LOW)
        GPIO.output(22,GPIO.HIGH)
        time.sleep(.2)
        GPIO.output(22,GPIO.LOW)

turn off 3 LED's

led-off-3.py

import RPi.GPIO as GPIO
 
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17,GPIO.OUT)
GPIO.setup(27,GPIO.OUT)
GPIO.setup(22,GPIO.OUT)
 
GPIO.output(17,GPIO.LOW)
GPIO.output(27,GPIO.LOW)
GPIO.output(22,GPIO.LOW)