Rev Up The Engine

The "Rev Up The Engine" application is an engaging Python-based project that combines hardware components and programming to simulate the experience of revving up a motorized engine. This project utilizes an SMD Motor Driver, a DC Motor, and a Push Button Module to allow users to control the speed of the engine by pushing and holding a button.

Project Key Components:

  1. SMD Motor Driver:

    • The SMD Motor Driver serves as the interface between the Python script and the DC Motor. It interprets commands from the script and translates them into actions that control the speed of the motor.

  2. DC Motor:

    • The DC Motor is connected to the SMD Motor Driver and represents the engine that the user can rev up.

  3. Push Button Module:

    • The Push Button Module is integrated into the project and serves as the user interface for controlling the engine speed. Pressing and holding the button initiates the revving process.

  4. Python Script:

    • The Python script is the central component of the application. It communicates with the SMD Motor Driver, reads the status of the Push Button Module, and adjusts the motor speed accordingly.

Project Key Features:

  1. Dynamic Engine Revving:

    • The Push Button Module allows users to simulate the experience of revving up an engine. Pressing and holding the button initiates the motor, and the speed gradually increases over time. Releasing the button results in a gradual decrease in speed until the motor eventually stops.

  2. Real-time Speed Control:

    • The Python script continuously monitors the status of the Push Button Module and adjusts the motor speed in real-time. This provides a responsive and interactive user experience.

  3. Customizable Speed Profile:

    • The script may include parameters to customize the speed profile, allowing users to adjust how quickly the motor accelerates and decelerates. This adds a layer of personalization to the engine revving simulation.

Project Wiring Diagram:

Getting Started:

  1. Hardware Setup:

    • Connect the DC Motor to the SMD Motor Driver following the provided documentation.

    • Integrate the Push Button Module into the setup, ensuring secure connections.

  2. Run the Application:

    • Execute the Python script, initiating the "Rev Up The Engine" application.

    • Press and hold the button on the Push Button Module to simulate revving up the engine.

  3. Experience the Engine Revving:

    • Observe how the DC Motor speed increases gradually while the button is held down.

    • Release the button and notice the motor speed decreasing until it comes to a stop.

  4. Customize and Experiment:

    • Experiment with different parameter values in the script to customize the speed profile.

    • Explore additional features, such as incorporating sound effects or visual indicators to enhance the simulation.

Project Codes:

from smd.red import*
import time
port = "COM13"
m = Master(port)
m.attach(Red(0))

print(m.scan_modules(0))

m.set_operation_mode(0, 0)
m.enable_torque(0, True)

button_prev = 0
pwm = 0

while True:
    time.sleep(0.05)
    button = m.get_button(0, 1)
    print(button)

    if button != None:
            if button == 1:
                if button_prev == 0:  # Button was just pressed
                    for pwm in range(51):
                        m.set_duty_cycle(0, pwm)
                        time.sleep(0.1)
                        red_value = int(pwm * 255 / 50)
                        green_value = int((50 - pwm) * 255 / 50)
                        light = m.set_rgb(0, 1, red=red_value, green=green_value, blue=0)
                        if pwm == 50:
                             m.set_buzzer(0, 1, 1000)  # Activate the buzzer
                    button_prev = 1
            elif button == 0:
                if button_prev == 1:  # Button was just released
                    for pwm in range(50, -1, -1):
                        m.set_duty_cycle(0, pwm)
                        time.sleep(0.1)
                        red_value = int(pwm * 255 / 50)
                        green_value = int((50 - pwm) * 255 / 50)
                        light = m.set_rgb(0, 1, red=red_value, green=green_value, blue=0)
                        if pwm == 0:
                            m.set_buzzer(0, 1, 0)  # Deactivate the buzzer

                    button_prev = 0


Last updated