Raspberry Pi 4 Project 01: Difference between revisions

From ikev.in/w
(Created page with "= LED Bar Graph Pulsating Project = This project involves creating a 10-LED bar graph that pulsates light using a Raspberry Pi 4 and Python code. The LED bar graph will have 10 bars, each controlled by a GPIO pin on the Raspberry Pi. == Required Materials == To complete this project, you will need the following materials: * Raspberry Pi 4 * Breadboard * 10 LEDs * 10 220-ohm resistors * Jumper wires == Circuit Diagram == The circuit diagram for this project is shown...")
 
No edit summary
Line 35: Line 35:


The Python code for this project is shown below:
The Python code for this project is shown below:
<pre>
    # Wait a short amount of time
    time.sleep(0.05)
# Decrease the duty cycle from 100 to 0 in steps of 5
for dc in range(100, -5, -5):
    # Set the duty cycle for each LED
    for i in range(len(led_pins)):
        GPIO.output(led_pins[i], dc > (i*10))
        # ^^^ If the duty cycle is greater than the threshold for this LED, turn it on.
    # Wait a short amount of time
    time.sleep(0.05)
</pre>

Revision as of 23:37, 21 April 2023

LED Bar Graph Pulsating Project

This project involves creating a 10-LED bar graph that pulsates light using a Raspberry Pi 4 and Python code. The LED bar graph will have 10 bars, each controlled by a GPIO pin on the Raspberry Pi.

Required Materials

To complete this project, you will need the following materials:

  • Raspberry Pi 4
  • Breadboard
  • 10 LEDs
  • 10 220-ohm resistors
  • Jumper wires

Circuit Diagram

The circuit diagram for this project is shown below:

In this diagram, each LED is connected to a GPIO pin on the Raspberry Pi through a 220-ohm resistor. The GPIO pins used for each LED are as follows:

  • LED 1: GPIO 21
  • LED 2: GPIO 20
  • LED 3: GPIO 16
  • LED 4: GPIO 12
  • LED 5: GPIO 7
  • LED 6: GPIO 8
  • LED 7: GPIO 25
  • LED 8: GPIO 24
  • LED 9: GPIO 23
  • LED 10: GPIO 18

Python Code

The Python code for this project is shown below:

    # Wait a short amount of time
    time.sleep(0.05)

# Decrease the duty cycle from 100 to 0 in steps of 5
for dc in range(100, -5, -5):
    # Set the duty cycle for each LED
    for i in range(len(led_pins)):
        GPIO.output(led_pins[i], dc > (i*10))
        # ^^^ If the duty cycle is greater than the threshold for this LED, turn it on.

    # Wait a short amount of time
    time.sleep(0.05)