Proj 324 Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Committer:
thomasmorris
Date:
Mon May 07 15:44:34 2018 +0000
Revision:
53:71f59e195f06
To test version of code;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thomasmorris 53:71f59e195f06 1 #include "mbed.h" //Include the mbed libraries
thomasmorris 53:71f59e195f06 2 #include "STEPPER_MOTOR.hpp" //Include the header file, this acts like a series of forward declarations
thomasmorris 53:71f59e195f06 3 #include "SERIAL_COMMANDS.hpp"
thomasmorris 53:71f59e195f06 4
thomasmorris 53:71f59e195f06 5 //Constructor
thomasmorris 53:71f59e195f06 6 STEPPER_MOTOR::STEPPER_MOTOR(PinName STEP, PinName DIRECTION) : _STEP(STEP), _DIRECTION(DIRECTION) //Constructor
thomasmorris 53:71f59e195f06 7 {
thomasmorris 53:71f59e195f06 8
thomasmorris 53:71f59e195f06 9 }
thomasmorris 53:71f59e195f06 10
thomasmorris 53:71f59e195f06 11 STEPPER_MOTOR::~STEPPER_MOTOR(){} //Destructor
thomasmorris 53:71f59e195f06 12 void STEPPER_MOTOR::Rotate_Steps(int Steps, int Direction)//Test this with the larger delay to see if that will increase the performance
thomasmorris 53:71f59e195f06 13 {
thomasmorris 53:71f59e195f06 14 _DIRECTION = Direction;
thomasmorris 53:71f59e195f06 15 for(int x =0 ; x < Steps; x++)
thomasmorris 53:71f59e195f06 16 {
thomasmorris 53:71f59e195f06 17 _STEP = 1;
thomasmorris 53:71f59e195f06 18 //wait_us(500);
thomasmorris 53:71f59e195f06 19 wait_ms(5);
thomasmorris 53:71f59e195f06 20 //Thread::wait(1);//wait 1 ms
thomasmorris 53:71f59e195f06 21 _STEP = 0;
thomasmorris 53:71f59e195f06 22 wait_ms(5);
thomasmorris 53:71f59e195f06 23 //wait_us(500);
thomasmorris 53:71f59e195f06 24 //Thread::wait(1);//wait 1ms
thomasmorris 53:71f59e195f06 25 }
thomasmorris 53:71f59e195f06 26 steps = 0;
thomasmorris 53:71f59e195f06 27 }
thomasmorris 53:71f59e195f06 28 void STEPPER_MOTOR::Permanent_Rotate_clock_wise()
thomasmorris 53:71f59e195f06 29 {
thomasmorris 53:71f59e195f06 30 _DIRECTION = 1;
thomasmorris 53:71f59e195f06 31 for(int x = 0; x< 200; x++)
thomasmorris 53:71f59e195f06 32 {
thomasmorris 53:71f59e195f06 33 _STEP = 1;
thomasmorris 53:71f59e195f06 34 wait_us(500);
thomasmorris 53:71f59e195f06 35 //Thread::wait(1);//wait 1 ms
thomasmorris 53:71f59e195f06 36 _STEP = 0;
thomasmorris 53:71f59e195f06 37 wait_us(500);
thomasmorris 53:71f59e195f06 38 //Thread::wait(1);//wait 1ms
thomasmorris 53:71f59e195f06 39 }
thomasmorris 53:71f59e195f06 40 }
thomasmorris 53:71f59e195f06 41 void STEPPER_MOTOR::Permanent_Rotate_anti_clock_wise()
thomasmorris 53:71f59e195f06 42 {
thomasmorris 53:71f59e195f06 43 _DIRECTION = 0;//For anti clockwise rotation
thomasmorris 53:71f59e195f06 44 for(int x = 0; x< 200; x++)
thomasmorris 53:71f59e195f06 45 {
thomasmorris 53:71f59e195f06 46 _STEP = 1;
thomasmorris 53:71f59e195f06 47 wait_us(500);
thomasmorris 53:71f59e195f06 48 //Thread::wait(1);//wait 1 ms
thomasmorris 53:71f59e195f06 49 _STEP = 0;
thomasmorris 53:71f59e195f06 50 wait_us(500);
thomasmorris 53:71f59e195f06 51 //Thread::wait(1);//wait 1ms
thomasmorris 53:71f59e195f06 52 }
thomasmorris 53:71f59e195f06 53 }
thomasmorris 53:71f59e195f06 54