Action - Reaction

The LED toggle application with a button is the most used project for simple input/output project example. This project allows the user to control the RGB module with the button module by simply toggling an LED.

Project Media:

Project Key Components:

  1. SMD Board

    The SMD board acts as a bridge between the script and the modules. It is responsible for interpreting the commands sent by the script and translating them into actions that read input from the button module and toggle the RGB module.

  2. RGB Module

    The RGB module is designed to emit different colors, allowing users to experiment with different lighting effects.

  3. Button Module

    The button module is the physical interface for receiving input from the user. The input can be used to trigger the script in an encoded way.

  4. SMD Libraries

    The SMD library is at the heart of the application. It communicates with the SMD board using a specific communication protocol, sending commands to read the button module and toggle the LED on the RGB module.

Project Key Features:

  1. A Basic Physical Interaction

    The application supports a toggle functionality, allowing the user to press the button to toggle the LED. This provides a simple physical interaction with project.

  2. Visualizing the Input

    The RGB module serves as a visual indicator of the current state of the button module. When the button is pressed, the LED turns on; when the button is not pressed, the LED turns off.

Project Wiring Diagram:

Getting Started:

  1. Hardware Setup:

    • Connect the SMD board to the PC or Arduino board using USB gateway module or Arduino gateway module.

    • Connect the RGB module and the button module to the SMD board using an RJ-45 cable.

    • Make sure that the SMD board is powered and all connections are correct.

  2. Run the Python Script:

    • Run the script on your computer. This will establish communication with the SMD board and initiate control of the button module and RGB module.

  3. Toggle LED State:

    • Press the button on the button module to toggle the RGB LED. Observe the visual feedback of the LED.

Projcet Codes:

from import *

SerialPort = "COM3"     # Serial port of the USB gateway module
baudrate = 115200       # Baud rate of communication
ID = 0                  # ID of the SMD board
rgb_module_id = 1       # ID of the RGB module
button_module_id = 1    # ID of the button module

master = Master(SerialPort, baudrate)       # Defines the USB gateway module
master.attach(Red(ID))                      # Gives acces to the SMD of specified ID

while True:
    button_state = master.get_button(ID, button_module_id)

    if button_state == 1:
        master.set_rgb(ID, rgb_module_id, 255, 0, 0)        # Numbers are correspond to the R - G - B color values
        master.set_rgb(ID, rgb_module_id, 0, 0, 0)          # Sets all colors to zero, meaning turning the RGB LED off

Last updated