In this video, I demonstrate how to control an LED using Raspberry Pi 5 and Python with the gpiozero library. The program turns the LED on and off before making it blink 5 times with a 2-second ON time and a 1-second OFF time.
🔹 Hardware Used: Raspberry Pi 5, LED, Resistor, Jumper Wires
🔹 Software: Python, GPIO Zero Library
🔹 Code Explanation: The script uses LED.on(), LED.off(), and LED.blink() functions to control the LED's behavior.
Code:
from gpiozero import LED
from time import sleep
Create an LED object on GPIO pin 17
led = LED(17)
Turn the LED on
led.on()
sleep(2) # Keep it on for 2 seconds
Turn the LED off
led.off()
sleep(2) # Keep it off for 2 seconds
Make the LED blink 5 times
led.blink(on_time=2, off_time=1, n=5,background=False) # 1 second on, 1 second off, repeat 5 ti
コメント