Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Stepper.h
00001 /* Stepper Motor 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 Stepper_H 00026 #define Stepper_H 00027 00028 #include "mbed.h" 00029 00030 /** Class library for a Stepper Motor to be able to Select amount of steps,set the time interval between steps, run stepper motor freely and stop the stepper motor. 00031 * 00032 * Example: 00033 * @code 00034 * #include "mbed.h" //include the mbed APIs and other libraries 00035 * #include "Stepper.h" //include the Stepper librariy 00036 * 00037 * Stepper stepper (PE_4, PE_5, PE_6, PE_7); //Initialize bus pins 00038 * 00039 * int main() 00040 * { 00041 * 00042 * while(1) //Enter infinite while loop 00043 * { 00044 * stepper.Interval(0.1); //Choosing time interval between steps(control speed) 00045 * stepper.Direction(true); //Choosing direction. true = Clockwise, false = Anticlockwise 00046 * stepper.Run(); //Makes the stepper run continuously 00047 * wait(5); //mbed's wait function, wait 5 sec. 00048 * stepper.Direction(false); 00049 * wait(5); 00050 * stepper.Stop(); //To make stepper stop 00051 * wait(5); 00052 * } 00053 * } 00054 * @endcode 00055 */ 00056 00057 class Stepper { 00058 public: 00059 /** Create a Stepper motor object connected to the specified pins. 00060 * @param coil1 MCU Output Pin for coil1. 00061 * @param coil2 MCU Output Pin for coil2. 00062 * @param coil3 MCU Output Pin for coil3. 00063 * @param coil4 MCU Output Pin for coil4. 00064 */ 00065 Stepper(PinName Coil1, PinName Coil2, PinName Coil3, PinName Coil4); 00066 00067 /** Makes the stepper run continuously. 00068 * @param 00069 * None 00070 */ 00071 void Run(); 00072 00073 /** To make stepper stop. 00074 * @param 00075 * None 00076 */ 00077 void Stop(); 00078 00079 /** Setting direction of the stepper motor, Clockwise or Anticlockwise. 00080 * @param 00081 * boolean slection to select direction. true = Clockwise, false = Anticlockwise 00082 */ 00083 void Direction(bool dir); 00084 00085 /** Choosing time interval between steps(control speed). 00086 * @param 00087 * A float value to set the time between steps. 00088 * @return 00089 * None 00090 */ 00091 void Interval(float sec); 00092 00093 /** Selct amount of steps the stpper motor should turn. 00094 * @param 00095 * interger value to select the amount of steps. 00096 * @return 00097 * None 00098 */ 00099 void Step(int steps); 00100 00101 private: 00102 00103 void stepper_isr(); 00104 00105 BusOut _Coils; 00106 Timer timer; 00107 Ticker ticker; 00108 float secinter; 00109 float lastsecinter; 00110 uint8_t StepDir; 00111 uint8_t stepper_steps[4]; 00112 int8_t stepcount; 00113 uint8_t Prevtime; 00114 uint8_t run; 00115 uint8_t stepincr; 00116 uint8_t stepping; 00117 uint8_t Steps; 00118 }; 00119 00120 #endif
Generated on Wed Jul 13 2022 00:05:57 by
1.7.2