LED toggle with button
📖 Scenario: You have a Raspberry Pi connected to an LED and a button. You want to control the LED so that each time you press the button, the LED turns on if it was off, and turns off if it was on.
🎯 Goal: Build a Python program that reads the button press and toggles the LED state accordingly.
📋 What You'll Learn
Use the
gpiozero library to control the LED and button.Create an LED object connected to GPIO pin 17.
Create a Button object connected to GPIO pin 2.
Toggle the LED state each time the button is pressed.
Print
LED is ON or LED is OFF after each toggle.💡 Why This Matters
🌍 Real World
This project shows how to control physical devices like LEDs using buttons, which is common in home automation and interactive electronics.
💼 Career
Understanding GPIO control and event-driven programming is useful for embedded systems, IoT development, and hardware prototyping jobs.
Progress0 / 4 steps