Newer
Older
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
#include <Stepper.h>
#include <ESP.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
const int rpm = 200;
const int MAXSTEPS = 10;
// for your motor
//asdfasdfasdf
const int PIN1 = D1;
const int PIN2 = D2;
const int PIN3 = D3;
const int PIN4 = D4;
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, PIN1, PIN2, PIN3, PIN4);
int stepCount = 0; // number of steps the motor has taken
int doSteps(int num_steps){
int numRevs = 0;
int do_count = num_steps / MAXSTEPS;
int count_remainder = num_steps % MAXSTEPS;
for(int i = 0; i < do_count; ++i){
myStepper.step(-MAXSTEPS);
//Serial.print("Increment: ");
if (i % 20 == 0){
Serial.printf("Number of Revolutions: %d\n", numRevs++);
}
ESP.wdtFeed(); //yield; feeds the watchdog (resets the software timer)
}
myStepper.step(count_remainder);
ESP.wdtFeed();
return numRevs;
}
void setup() {
ESP.wdtDisable();
pinMode(PIN1, OUTPUT);
pinMode(PIN2, OUTPUT);
pinMode(PIN3, OUTPUT);
pinMode(PIN4, OUTPUT);
Serial.begin(115200);
myStepper.setSpeed(rpm);
// step 1/100 of a revolution:
int numRevolutions = (int) 1e5;
doSteps(numRevolutions * stepsPerRevolution);
Serial.println(stepCount);
}
void loop() {
ESP.wdtFeed();
//delay(500);
}