Thomas Morris / Mbed OS PROJ324_Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers STEPPER_MOTOR.cpp Source File

STEPPER_MOTOR.cpp

00001 #include "mbed.h"           //Include the mbed libraries
00002 #include "STEPPER_MOTOR.hpp"          //Include the header file, this acts like a series of forward declarations
00003 #include "SERIAL_COMMANDS.hpp"
00004 
00005 //Constructor
00006 STEPPER_MOTOR::STEPPER_MOTOR(PinName STEP, PinName DIRECTION) : _STEP(STEP), _DIRECTION(DIRECTION) //Constructor
00007 {
00008 
00009 }
00010 
00011 STEPPER_MOTOR::~STEPPER_MOTOR(){}   //Destructor
00012 void STEPPER_MOTOR::Rotate_Steps(int Steps, int Direction)//Test this with the larger delay to see if that will increase the performance
00013 {
00014        _DIRECTION = Direction;
00015        for(int x =0 ; x < Steps; x++)
00016         {
00017             _STEP = 1;
00018             //wait_us(500);
00019             wait_ms(5);
00020             //Thread::wait(1);//wait 1 ms 
00021             _STEP = 0;
00022             wait_ms(5);
00023             //wait_us(500);
00024             //Thread::wait(1);//wait 1ms
00025         }
00026         steps = 0;
00027 }
00028 void STEPPER_MOTOR::Permanent_Rotate_clock_wise()
00029 {
00030     _DIRECTION = 1;
00031     for(int x = 0; x< 200; x++)
00032     {
00033         _STEP = 1;
00034         wait_us(500);
00035         //Thread::wait(1);//wait 1 ms 
00036         _STEP = 0;
00037         wait_us(500);
00038         //Thread::wait(1);//wait 1ms
00039     }
00040 }
00041 void STEPPER_MOTOR::Permanent_Rotate_anti_clock_wise()
00042 {
00043     _DIRECTION = 0;//For anti clockwise rotation
00044     for(int x = 0; x< 200; x++)
00045     {
00046         _STEP = 1;
00047         wait_us(500);
00048         //Thread::wait(1);//wait 1 ms 
00049         _STEP = 0;
00050         wait_us(500);
00051         //Thread::wait(1);//wait 1ms
00052     }
00053 } 
00054