Class library for a L298 H-Bridge

Dependents:   inverted_pendulum_system

Fork of L298HBridge by Riaan Ehlers

L298HBridge.h

Committer:
RiaanEhlers
Date:
2017-01-19
Revision:
1:6d242bb216d6
Parent:
0:39561fe6e4ff
Child:
2:1c000b6cf863

File content as of revision 1:6d242bb216d6:

/* L298HBridge Library v1.0
 * Copyright (c) 2017 Riaan Ehlers
 * riaan.ehlers@nmmu.ac.za
 *
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
 
#ifndef L298HBridge_H
#define L298HBridge_H
 
#include "mbed.h"
 
/** Class library for a L298 H-Bridge.
 *
 * Example:
 * @code
 * 
 * @endcode
 */
 
class L298HBridge {
  public:
    /** 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" direction (neither forward or reverse).
    * @param ENPin PwmOut compatible pin used to connect to L298's En pin associated with enabling the H-Bridge.
    * @param FWDPin GPIO pin used to connect to L298's In pin associated with forward direction.
    * @param REVPin GPIO pin used to connect to L298's In pin associated with reverse direction.
    */
    L298HBridge(PinName ENPin, PinName FWDPin, PinName REVPin);
    
    /** Switch the H-Bridge to run the motor in the forward direction.    
    * @param None
    */
    void Fwd();
    
    /** Switch the H-Bridge to run the motor in the reverse direction.    
    * @param None
    */
    void Rev();
    
    /** Switch the H-Bridge off. The H-Bridge is not set to forward or reverse. 
    * @param None
    */
    void Stop();
    
   /** Change the motor's speed by adjusting the PWM signal.       
    * @param int DutyPercent
    */
    void Speed(int DutyPercent);
 
  private:
    PwmOut _ENPin;
    DigitalOut _FWDPin, _REVPin;
};
 
#endif