forked from rkaczorek/AdafruitStepperMotorHAT_CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Adafruit_MotorHAT.h
executable file
·84 lines (62 loc) · 1.38 KB
/
Adafruit_MotorHAT.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once
#include <vector>
#include <wiringPi/wiringPi.h>
#include <wiringPi/softPwm.h>
enum Direction {
FORWARD,
BACKWARD,
BRAKE,
RELEASE
};
enum Style {
SINGLE,
DOUBLE,
INTERLEAVE,
MICROSTEP
};
class Adafruit_MotorHAT;
class Adafruit_StepperMotor {
public:
static const int MICROSTEPS=8;
static const unsigned char MICROSTEP_CURVE[9];
Adafruit_StepperMotor(Adafruit_MotorHAT* hat, int num, int steps=200);
Adafruit_MotorHAT* hat;
int PWMA;
int AIN2;
int AIN1;
int PWMB;
int BIN2;
int BIN1;
int coils[4];
static const int step2coils[8][4];
int revsteps;
int motornum;
float sec_per_step;
int steppingcounter;
int currentstep;
void setSpeed(int rpm);
int oneStep(Direction dir, Style style);
void step(int steps, Direction direction, Style stepstyle);
};
class Adafruit_DCMotor {
public:
Adafruit_DCMotor(Adafruit_MotorHAT* _hat, int num);
Adafruit_MotorHAT* hat;
int PWM;
int IN2;
int IN1;
int motornum;
void run(Direction dir);
void setSpeed(int speed);
};
class Adafruit_MotorHAT {
public:
int _frequency;
std::vector<Adafruit_StepperMotor> steppers;
std::vector<Adafruit_DCMotor> dcs;
Adafruit_MotorHAT(int addr = 0x60, int freq = 1600, int i2c=-1, int i2c_bus=-1);
void setPin(int pin, int value);
Adafruit_StepperMotor& getStepper(int num);
Adafruit_DCMotor& getDC(int num);
void resetAll();
};