-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStepper.cpp
More file actions
40 lines (32 loc) · 794 Bytes
/
Stepper.cpp
File metadata and controls
40 lines (32 loc) · 794 Bytes
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
#include "Stepper.h"
Stepper::Stepper(int _numSteps, int _timePerStep) {
numSteps = _numSteps;
timePerStep = _timePerStep;
lastStepTime = 0;
}
void Stepper::process() {
if (millis() > lastStepTime + timePerStep) {
lastStepTime = millis();
nextStep();
stepCallback(currentStep);
}
}
void Stepper::nextStep() {
currentStep++;
if (currentStep >= numSteps) {
currentStep = 0;
maxStepCallback();
}
}
void Stepper::maxStepHandler(void (*f)()) { // add this for extra parameter/control input, when number of step reached its maximum
maxStepCallback = *f;
}
void Stepper::setTimePerStep(int _timePerStep) {
timePerStep = _timePerStep;
}
void Stepper::stepHandler(void (*f)(int)) {
stepCallback = *f;
}
void Stepper::stepReset() {
currentStep = 0;
}