Armand Coetzer / L298HBridge
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers L298HBridge.h Source File

L298HBridge.h

00001 /* L298HBridge Library v1.0
00002  * Copyright (c) 2017 Armand Coetzer
00003  * s213293048@nmmu.ac.za
00004  *
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy
00007  * of this software and associated documentation files (the "Software"), to deal
00008  * in the Software without restriction, including without limitation the rights
00009  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010  * copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be included in
00014  * all copies or substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022  * THE SOFTWARE.
00023  */
00024  
00025 #ifndef L298HBridge_H
00026 #define L298HBridge_H
00027  
00028 #include "mbed.h"
00029  
00030 /** Class library for a L298 H-Bridge.
00031  *
00032  * Example:
00033  * @code
00034  * #include "mbed.h"
00035  * #include "L298HBridge.h"
00036  *
00037  * L298HBridge dcmotor(PA_5, PA_6, PA_10); //Create a L298HBridge object with enable pin on PA5, Fwd pin or PA6 and Rev pin on PA10
00038  *
00039  * int main() 
00040  * {
00041  *    while(1)
00042  *    {
00043  *          dcmotor.Fwd();               //setting the motor to spin forward
00044  *          dcmotor.SetSpeed(0.5);       //setting the speed the motor will spin
00045  *    }    
00046  * }
00047  * @endcode
00048  */
00049  
00050 class L298HBridge {
00051   public:
00052     /** Create a L298HBridge object connected to the specified pins. Once created, The pins still need
00053     * to be set to a direction and also the speed via PWM.
00054     * @param ENpin PwmOut compatible pin used to set the speed of the motor.
00055     * @param FWDpin Used to spin the motor in the forward direction.
00056     * @param REVDpin Used to spin the motor in the Reverse direction.
00057     */
00058     L298HBridge(PinName ENpin, PinName FWDpin, PinName REVpin);
00059     
00060     /** Setting the DC motor to spin in the forward direction.
00061     * @param 
00062     *     None
00063     */
00064     void Fwd();
00065     
00066     /** Setting the DC motor to spin in the Revers direction.
00067     * @param 
00068     *     None
00069     */
00070     void Rev();
00071     
00072      /** Stopping the motor.
00073     * @param 
00074     *     None
00075     */
00076     void Stop();
00077     
00078      /** Set the speed of the motor.
00079     * @param 
00080     *     PWMPercentage, variable to set te speed of the motor (any value from 0.1 - 1).
00081     * @return
00082     *     None
00083     */
00084     void SetSpeed(float PWMPercentage);
00085  
00086   private:
00087     PwmOut _en;
00088     DigitalOut _fwd, _rev;
00089 };
00090  
00091 #endif