Class library for a L298 H-Bridge

L298HBridge.h

Committer:
Armand
Date:
2017-02-14
Revision:
0:85a98c7707c9
Child:
1:0af00b1a2b52

File content as of revision 0:85a98c7707c9:

/* L298HBridge Library v1.0
 * Copyright (c) 2017 Armand Coetzer
 * xxxxxxxxxx@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 HC-SR04 Distance Sensor based on PwmOut (Trig) and InterruptIn (Echo).
 *
 * Example:
 * @code
 * #include "mbed.h"
 * #include "HCSR04.h"
 *
 * HCSR04 distance(PB_8, PA_1);
 *
 * int main() {
 *     while(1){
 *         SWO.printf("Distance = %d (us)   %f (cm)\n", distance.read_us(), distance.read_cm()); 
 *     }
 * }
 * @endcode
 */
 
class L298HBridge {
  public:
    /** Create a L298HBridge object connected to the specified pins. Once created, the PWM signal
    * on the Trig pin will start immediately and measurements will start in the background.
    * @param ENpin PwmOut compatible pin used to connect to HC-SR04's Trig pin
    * @param FWDpin InterruptIn compatible pin used to connect to HC-SR04's Echo pin
    */
    L298HBridge(PinName ENpin, PinName FWDpin, PinName REVpin);
    
    /** Return the current pulse duration as microseconds (us).
    * @param 
    *     None
    */
    void Fwd();
    
    /** Return the current pulse duration as centimeters (cm).
    * @param 
    *     PWMPercentage Gjhgjhgsjsgdjhsgdjhsgd
    * @return
    *     None
    */
    void Speed(float PWMPercentage);
 
  private:
    PwmOut _en;
    DigitalOut _fwd, _rev;
};
 
#endif