Select Page

Connecting LED

 


Turn on a LED

import RPi.GPIO as GPIO
import time

ledPin=40
GPIO.setmode(GPIO.BOARD)
GPIO.setup(ledPin, GPIO.OUT)
GPIO.output(ledPin, GPIO.HIGH)
time.sleep(5)
GPIO.output(ledPin, GPIO.LOW)
GPIO.cleanup()

Blink an LED 20 times

import RPi.GPIO as GPIO
import time

ledPin=40
GPIO.setmode(GPIO.BOARD)
GPIO.setup(ledPin, GPIO.OUT)

for i in range(1,20):
 GPIO.output(ledPin, GPIO.HIGH)
 time.sleep(0.25)
 GPIO.output(ledPin, GPIO.LOW)
 time.sleep(0.25)

GPIO.cleanup()