Acrome-SMD Docs
All Acrome ProductsReferencesBlogCase StudiesContact Us
  • ACROME SMD
  • Electronics
    • 🔴SMD Red
      • Troubleshooting Guide
    • 🔵SMD Blue
    • 🟢SMD Green
    • Gateway Modules
      • Arduino Gateway Module
      • USB Gateway Module
    • Electrical Motors
      • Brushed DC Motors (BDC)
      • Stepper DC Motors (SDC)
      • Brushless DC Motor (BLDC)
      • Linear Actuator with Feedback – 75 lbs
    • Add-on Modules
      • Ambient Light Sensor Module
      • Button Module
      • Buzzer Module
      • IMU Module
      • Joystick Module
      • Potentiometer Module
      • Reflectance Sensor Module
      • RGB LED Module
      • Servo Module
      • Ultrasonic Distance Sensor Module
  • SMD Kits
    • Starter Kit
      • What You Can Build
    • Education Kit
      • What You Can Build
    • Motion Kit
      • What You Can Build
  • Software
    • Libraries
      • Python Library
      • Arduino Library
      • Java Library
      • Matlab Library
    • SMD UI
    • SMD Blockly
      • Introducing Customized Blockly Blocks
  • SMD Applications
    • Basics
      • Blink
      • Action - Reaction
      • Autonomous Lighting
      • Smart Doorbell
      • Security System
      • Distance Buzzer Warning
      • Distance Auto Stop
      • Smart Light Control
    • Interactive
      • Automatic Trash Bin
      • Radar
      • Chrome Dino Game Player
      • Play Chrome Dino Game With Joystick
      • Snake Game With Joystick
      • Pan-Tilt with Joystick Module
      • Joystick Mouse Control
      • Rev Up the Engine
      • Motor Rotation Based on Turn Input Value
      • Basic Motor Speed Control Application
      • Basic Motor Control Application Using PWM Input
      • Basic Motor Position Control Application
      • Basic Motor Torque Control Application
      • Motor Rotation Based on Joystick Counting
    • Robotics
      • Differential Robot Projects
      • Mouse Cursor Tracker Motion Robot
      • Waypoint tracker robot
      • Braitenberg Robot
      • Line-Follower Robot
      • Teleoperation Robot
      • Obstacle Avoidance Robot
      • ESP32 Wireless Controlled Mobile Robot
  • AI
    • Object Tracking Robot
    • Groq Chatbot-Controlled Robot
  • ROS
    • Teleoperation Robot with ROS
  • Mechanics
    • Building Set
      • Plates
        • 2x2 Plate Package
        • 2x3 120° Plate Package
        • 3x3 Plate Package
        • 3x5 Plate Package
        • 3x9 Plate Package
        • 11x19 Plate
        • 9x19 Plate
        • 5x19 Plate
        • 3x19 Plate
        • 9x11 Plate
        • 5x13 Plate
      • Joints
        • 60° Joint Package
        • 90° Joint Package
        • 120° Joint Package
        • Slot Joint M2 Package
        • Slot Joint M3 Package
        • U Joint Package
      • Mounts
        • Add-on Mount Package
        • Motor L Mount Package
        • Pan-Tilt Package
      • Wheels
        • Ball Wheel Package
        • Caster Wheel Package
        • Wheel Package
      • Cables
        • Power Cable 10 cm Package
        • Power Cable 20 cm Package
        • Power Cable 35 cm Package
        • RJ-11 Cable 7.5 cm Package
        • RJ-11 Cable 20 cm Package
        • RJ-11 Cable 35 cm Package
        • RJ-45 Cable 7.5 cm Package
        • RJ-45 Cable 20 cm Package
        • RJ-45 Cable 35 cm Package
      • Fasteners
        • M2x5 Allen Hex Screw Package
        • M3x6 Allen Hex Screw Package
        • M3x8 Allen Hex Screw Package
        • M3 Hex Nut Package
  • Help
    • Manual
    • Shops
    • Reach Us
Powered by GitBook
On this page
  • Step 1: Hardware & Software Overview
  • Step 2: Assemble
  • Step 3: Run & Test
  • Codes
  1. SMD Applications
  2. Basics

Action - Reaction

PreviousBlinkNextAutonomous Lighting

Last updated 2 months ago

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 with the by simply toggling an LED.

About Tools and Materials:

()

Step 1: Hardware & Software Overview

Project Key Components

Project Key Features

  • 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.

  • Visualizing the Input

Step 2: Assemble

Getting Started

  1. Hardware Setup

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

Project Wiring Diagram

Step 3: Run & Test

  1. Run the Script

  2. Toggle LED State

Codes

from serial.tools.list_ports import comports
from platform import system
from smd.red import *

baudrate = 115200       # Baud rate of communication
ID = 0                  # ID of the SMD
rgb_module_id = 5       # ID of the RGB LED module
button_module_id = 5    # ID of the button module


def USB_Port():
    """
    Scans and identifies a compatible USB port for the current operating system.

    Returns:
        str: The detected USB port or None if no suitable port is found.
    """
    # Get a list of available ports
    ports = list(comports())
    
    # Known USB port names for different operating systems
    usb_names = {
        "Windows": ["USB Serial Port"],  # Names specific to Windows
        "Linux": ["/dev/ttyUSB"],        # Names specific to Linux
        "Darwin": [                      # Names specific to macOS
            "/dev/tty.usbserial",
            "/dev/tty.usbmodem",
            "/dev/tty.SLAB_USBtoUART",
            "/dev/tty.wchusbserial",
            "/dev/cu.usbserial",
        ]
    }

    # Detect the operating system
    os_name = system()
    print(f"Operating System: {os_name}")

    if ports:
        for port, desc, hwid in sorted(ports):
            # Check if the port matches any known USB names
            if any(name in port or name in desc for name in usb_names.get(os_name, [])):
                print(f"USB device detected on port: {port}")
                return port  # Return the first matching port
        # If no suitable port is found, print the list of available ports
        print("No suitable USB device found. Available ports:")
        for port, desc, hwid in ports:
            print(f"Port: {port}, Description: {desc}, HWID: {hwid}")
    else:
        print("No ports detected!")
    return None


try:
    # Find a valid serial port
    SerialPort = USB_Port()
    if not SerialPort:
        raise Exception("No compatible USB port found. Please check your connection.")

    print(f"Using serial port: {SerialPort}")

    # Initialize the SMD module
    master = Master(SerialPort, baudrate)       # Defines the USB gateway module
    master.attach(Red(ID))                      # Gives access to the SMD of specified ID
    master.scan_modules(ID)                     # Scans and identifies the modules connected to the SMD

    # Main loop
    while True:
        # Get the button state from the SMD
        button_state = master.get_button(ID, button_module_id)

        if button_state == 1:
            # Set the RGB LED to red
            master.set_rgb(ID, rgb_module_id, 255, 0, 0)  # RGB values for red
        else:
            # Turn off the RGB LED
            master.set_rgb(ID, rgb_module_id, 0, 0, 0)    # RGB values for off

except Exception as e:
    print(f"Error: {e}")
#include <Acrome-SMD.h>

#define ID        0           // ID of the SMD
#define BAUDRATE  115200      // Baud rate of the communication

Red master(ID, Serial, BAUDRATE);    // Defines the Arduino gateway module

int rgb_module_id = 1;              // ID of the RGB LED module
int button_module_id = 1;           // ID of the button module

int button_state = 0;               // Variable to store the button state

void setup() {
    master.begin();                 // Starts the communication
    master.scanModules();           // Scans for the connected modules
}

void loop() {
    button_state = master.getButton(button_module_id);      // Getting the button state and storing it
    
    if (button_state == 1) {
        master.setRGB(rgb_module_id, 255, 0, 0);    // Numbers are correspond to the R - G - B color values
    }

    else {
        master.setRGB(rgb_module_id, 0, 0, 0);      // Sets all colors to zero, meaning turning the RGB LED off
    }
}

()

()

()

()

The SMD 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 .

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

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

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

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

Connect the SMD to the PC or Arduino board using or .

Connect the and the to the SMD using an RJ-45 cable.

Run the script on your computer. This will establish communication with the SMD and initiate control of the and .

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

SMD USB Gateway
Purchase Here
Arduino Gateway Module
Purchase Here
RGB LED Module
Purchase Here
Button Module
Purchase Here
SMD
RGB LED Module
RGB LED Module
RGB LED Module
Button Module
Button Module
SMD Libraries
Button Module
RGB LED Module
RGB LED Module
Button Module
USB Gateway Module
Arduino Gateway Module
RGB LED Module
Button Module
Button Module
RGB LED Module
Button Module
RGB LED Module
Button Module
SMD Red
Purchase Here