Basic I/O components
This module provides classes to manage common input/output components, such as buttons and LEDs, with support for PWM-based brightness control for LEDs. The classes allow for checking button states, toggling LEDs, blinking LEDs, and controlling brightness and fading effects using PWM.
Example
from hw_config import Led
led = Led(2)
print("LED blinking...")
led.blink(times=3)
print("Toggling LED...")
led.toggle()
# Example of using the PwmLed class
led = PwmLed(2)
print("Fading in...")
led.fade_in(duration=2)
Modification history
2024-11-11 : Added Sphinx-style comments for documentation.
2024-10-26 : Added demo method to demonstrate usage of the classes.
2024-09-28 : File created, initial release.
- class hw_config.Button(pin_number)[source]
Bases:
object
A class to manage a button connected to a GPIO pin with a pull-up resistor.
- class hw_config.Led(*args: Any, **kwargs: Any)[source]
Bases:
Pin
A class to control an LED connected to a specified GPIO pin.
- class hw_config.PwmLed(*args: Any, **kwargs: Any)[source]
Bases:
PWM
A class to control an LED using PWM, allowing for brightness adjustment, fading, and on/off control.
- fade_in(duration=1)[source]
Gradually increase the brightness to create a fade-in effect.
- Parameters:
duration – Total duration of the fade-in effect, in seconds. Default is 1 second.
- fade_out(duration=1)[source]
Gradually decrease the brightness to create a fade-out effect.
- Parameters:
duration – Total duration of the fade-out effect, in seconds. Default is 1 second.