새기능 #3
진행중[튜토리얼] LED 제어
100%
설명
Sure, here are some Raspberry Pi LED control sample codes using Python.
There are two primary ways to control LEDs on a Raspberry Pi:
Using RPi.GPIO library: This is the traditional and most common way to directly control the GPIO pins.
Using gpiozero library: This is a newer, higher-level library that simplifies common GPIO tasks, including LED control, by providing object-oriented interfaces. It's often recommended for beginners due to its simplicity.
Let's look at examples for both.
Using RPi.GPIO Library (Basic Control)
This method gives you fine-grained control over individual GPIO pins.
Requirements:
Raspberry Pi (any model)
LED
220-330 ohm resistor (current limiting for the LED)
Jumper wires
Breadboard (optional but recommended)
Wiring:
Connect the components as follows:
LED Long Leg (Anode) ↔ Resistor ↔ Raspberry Pi GPIO Pin (e.g., GPIO 17)
LED Short Leg (Cathode) ↔ Raspberry Pi GND Pin