LED class and methods
📖 Scenario: You have a Raspberry Pi connected to an LED light. You want to control the LED by turning it on and off using a simple program.
🎯 Goal: Create a class called LED that can turn the LED on and off using methods. Then, use this class to turn the LED on and off.
📋 What You'll Learn
Create a class named
LEDAdd an
__init__ method that takes a pin number and stores itAdd a method
turn_on that prints "LED on pin X is ON" where X is the pin numberAdd a method
turn_off that prints "LED on pin X is OFF" where X is the pin numberCreate an instance of
LED with pin number 17Call
turn_on and turn_off methods on the instance💡 Why This Matters
🌍 Real World
Controlling hardware like LEDs on a Raspberry Pi is common in home automation and robotics projects.
💼 Career
Understanding how to create classes and methods to control hardware devices is useful for embedded systems and IoT developer roles.
Progress0 / 4 steps