-
Notifications
You must be signed in to change notification settings - Fork 0
/
AllegroStepper.cpp
48 lines (42 loc) · 1.11 KB
/
AllegroStepper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* AllegroStepper.cpp
*
* Created on: Jul 9, 2015
* Author: Jacob
*/
#include "AllegroStepper.h"
#include <Arduino.h>
//Constructor: Set up pins
AllegroStepper::AllegroStepper(byte step_Pin, byte dir_Pin, byte enable_Pin) {
stepPin = step_Pin;
dirPin = dir_Pin;
enablePin = enable_Pin;
}
//Initialize: set up pins for output
void AllegroStepper::initialize()
{
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(enablePin,OUTPUT);
disable(); //start with motors disabled
digitalWrite(stepPin, LOW); //actively dkeep step pin low
}
void AllegroStepper::enable() //enables stepper motor driver. Keeps enable pin low.
{
digitalWrite(enablePin,LOW);
enabled = true;
}
void AllegroStepper::disable() //disables stepper motor driver. Keeps enable pin high.
{
digitalWrite(enablePin,HIGH);
enabled = false;
}
void AllegroStepper::step(byte dir) //Executes a single step
{
if (!enabled) //check if driver is enabled, and keep
enable();
digitalWrite(dirPin,dir); //set direction
digitalWrite(stepPin,HIGH); //execute step
delayMicroseconds(5); //wait before
digitalWrite(stepPin,LOW); //put step pin low
}