Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TStepper{
- int g_stepPin = 3;
- int g_dirPin = 4;
- int g_stepsPerRev = 200;
- int g_dirPinState = 1;
- private:
- uint8_t getDirection(char* dirParam){
- if (dirParam=="clockwise"){
- //dirPinState = 1;
- return 1;
- }else if (dirParam=="anticlockwise"){
- return 0;
- //dirPinState = 0;
- }
- }
- public:
- TStepper(int stepPin, int dirPin, int stepsPerRev){ //constructor
- pinMode(stepPin,OUTPUT);
- pinMode(dirPin,OUTPUT);
- g_stepPin = stepPin;
- g_dirPin = dirPin;
- g_stepsPerRev = stepsPerRev;
- }
- //1.8 deg per step calced with (360/200)
- void rotate(char* direction, int angle){
- // g_dirPinState = getDirection(direction);
- //digitalWrite(g_dirPin,g_dirPinState); //Changes the rotations direction
- // Makes 400 pulses for making two full cycle rotation
- int angleToSteps = (360/g_stepsPerRev);
- int stepMax = angle/angleToSteps;
- step(stepMax,g_dirPinState);
- }
- void step(int stepCount, char* direction){
- g_dirPinState = getDirection(direction);
- digitalWrite(g_dirPin,g_dirPinState); //Changes the rotations direction
- for(int x = 0; x < stepCount; x++) {
- digitalWrite(g_stepPin,HIGH);
- delayMicroseconds(1000);
- digitalWrite(g_stepPin,LOW);
- delayMicroseconds(1000);
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement