H Bridge
This driver controls the direction and speed of two motors using a L298N H-Bridge circuit with PWM signals. It also manages braking functionality.
Initialization
This must be called before any other H Bridge function in your program. After initialization, the H Bridge is set to idle speed, ready to receive speed commands.
Parameters:
· Motor1_Speed & Motor2_Speed: PWM channels for controlling the speed of Motor 1 and Motor 2.
· Motor1_Forward & Motor1_Backward: Digital I/O channels for setting the direction of Motor 1.
· Motor2_Forward & Motor2_Backward: Digital I/O channels for setting the direction of Motor 2.
Setting speed
This function is used for setting specific speeds. It takes integer values between -100 and 100, with -100 being full speed backward and 100 being full speed forward.
Parameters:
· Speed: An integer value between -100 and 100, where positive values indicate forward motion and negative values indicate reverse motion.
Braking
This function allows you to override the set speed and brake the car. After braking, any calls to set the speed will not work. You must set the brake to 0 again to resume control of the motors.
Parameters:
· Brake: The car will brake if set to anything other than 0 (Ex. 1). Setting it to 0 disengages the brake and allows the car to speed up.
Parameters:
· Brake: The car will brake if set to anything other than 0 (Ex. 1). Setting it to 0 disengages the brake and allows the car to speed up.
Getting speed
This function is used to get the last speed value set.
Getting brake
This function is used to get the last brake value set.
Last updated