-
Notifications
You must be signed in to change notification settings - Fork 7
/
StepperMotorTest.cpp
38 lines (30 loc) · 1023 Bytes
/
StepperMotorTest.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
#include "Adafruit_MotorHAT.h"
#include "stdio.h"
#include <iostream>
#include <signal.h>
Adafruit_MotorHAT hat;
void ctrl_c_handler(int s){
std::cout << "Caught signal " << s << std::endl;
hat.resetAll();
exit(1);
}
int main(int argc, char** argv) {
signal(SIGINT, ctrl_c_handler);
auto& myStepper = hat.getStepper(1); // # motor port #1
std::cout << "Got stepper" << std::endl;
myStepper.setSpeed(30); // # 30 RPM
while (true) {
std::cout << "Single coil steps" << std::endl;
myStepper.step(100, FORWARD, SINGLE);
myStepper.step(100, BACKWARD, SINGLE);
std::cout << "Double coil steps" << std::endl;
myStepper.step(100, FORWARD, DOUBLE);
myStepper.step(100, BACKWARD, DOUBLE);
std::cout << "Interleaved coil steps" << std::endl;
myStepper.step(100, FORWARD, INTERLEAVE);
myStepper.step(100, BACKWARD, INTERLEAVE);
std::cout << "Microsteps" << std::endl;
myStepper.step(100, FORWARD, MICROSTEP);
myStepper.step(100, BACKWARD, MICROSTEP);
}
}