Class library for a L298 H-Bridge to be used for motor control.

Embed: (wiki syntax)

« Back to documentation index

L298HBridge Class Reference

L298HBridge Class Reference

Class library for a L298 H-Bridge. More...

#include <L298HBridge.h>

Public Member Functions

 L298HBridge (PinName ENPin, PinName FWDPin, PinName REVPin)
 Create a L298HBridge object connected to the specified pins.
void Fwd ()
 Configure the H-Bridge to run the motor in the forward direction.
void Rev ()
 Configure the H-Bridge to run the motor in the reverse direction.
void Stop ()
 Switch the H-Bridge off.
void Speed (float DutyPercent)
 Change the motor's speed by adjusting the PWM signal.

Detailed Description

Class library for a L298 H-Bridge.

The class is written for one H-Bridge of the L298. Constructing the class twice will enable you to use both H-bridges.

Example:

 #include "mbed.h"
 #include "L298HBridge.h"

 L298HBridge Motor(PB_4, PC_4, PC_5);
   
 int main() 
 {
    float i;
    while(1) 
    {
        Motor.Fwd();
       
        for(i=0;i<100;i++)
        {
            Motor.Speed(i);
            wait(0.1);
        }
                
        for(i=100;i>25;i--)
        {
            Motor.Speed(i);
            wait(0.1);
        }
        
        Motor.Rev();
                
        for(i=0;i<100;i++)
        {
            Motor.Speed(i);
            wait(0.1);
        }
                
        for(i=100;i>25;i--)
        {
            Motor.Speed(i);
            wait(0.1);
        }
    }
 }

Definition at line 77 of file L298HBridge.h.


Constructor & Destructor Documentation

L298HBridge ( PinName  ENPin,
PinName  FWDPin,
PinName  REVPin 
)

Create a L298HBridge object connected to the specified pins.

Once created, the motor speed will be set to 0 (PWM signal will be 0%) and the motor will be in the stop mode (neither forward or reverse).

Parameters:
ENPinPwmOut compatible pin used to connect to L298's En(x) pin associated with enabling the H-Bridge.
FWDPinGPIO pin used to connect to L298's In(x) pin associated with forward direction.
REVPinGPIO pin used to connect to L298's In(x) pin associated with reverse direction.

Definition at line 5 of file L298HBridge.cpp.


Member Function Documentation

void Fwd (  )

Configure the H-Bridge to run the motor in the forward direction.

Parameters:
None

Definition at line 12 of file L298HBridge.cpp.

void Rev (  )

Configure the H-Bridge to run the motor in the reverse direction.

Parameters:
None

Definition at line 17 of file L298HBridge.cpp.

void Speed ( float  DutyPercent )

Change the motor's speed by adjusting the PWM signal.

The value passed to the function can be any value from 0 to 100. Where 0 = 0% and 100 = 100%.

Parameters:
DutyPercent

Definition at line 27 of file L298HBridge.cpp.

void Stop (  )

Switch the H-Bridge off.

The H-Bridge is not set to forward or reverse.

Parameters:
None

Definition at line 22 of file L298HBridge.cpp.