Digital output, it is very wonderful features of a Raspberry Pi(RPi), RPi has some GPIO pins(General Purpose Input Output) which is helps to give digital data to digital output devices like led, Relay, Seven segment, led cube, led matrix etc.
In Digital world mainly two things are their which is ON & OFF; in uP language we can say that is 1 & 0 or 5v & Gnd. In case of RPi GPIO pin generate 5v or high signal to turn on led and gnd or low signal to turn off led.
So lets start how its work !!!Â
CIRCUIT CONNECTION:
CODE:
import RPi.GPIO as GPIO ## Import GPIO library
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(3, GPIO.OUT) ## Setup Pin 3 to OUTPUT
while True:
#Infinite Loop
GPIO.output(3, True) ## Turn on pin 3
print ("led on")
time.sleep(1)
GPIO.output(3,False) ## Turn off pin 3
print ("led off")
time.sleep(1)
NOTE:
- Save above code in .py
- E.g.: led_blink.py
- Run code in terminal
python led_blink.py
If use Thonny IDE