Skip to content

Commit a57fe33

Browse files
committed
This will get your motors turning
1 parent b59895f commit a57fe33

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

motor_workshop.ino

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <Stepper.h>
2+
3+
// THIS IS STEPS PER REVOLUTION BEFORE GEARS
4+
#define STEPS_PER_REVOLUTION_INTERNAL 32
5+
6+
// GEAR RATIO IS 1:64, SO 32 * 64 = 2048
7+
#define STEPS_PER_REVOLUTION 32 * 64
8+
9+
// INSTANCE OF THE LIBRARY CLASS!
10+
// PARAMETERS: steps/rev, pin 1, pin 2, pin 3, pin 4
11+
Stepper motor(STEPS_PER_REVOLUTION_INTERNAL, 8, 10, 9, 11);
12+
13+
/* IT IS A GOOD PRACTICE TO DECLARE ESSENTIAL VARIABLES AS GLOBALS
14+
FOR ARDUINO, THIS HELPS TO AVOID OUT OF MEMORY CONDITIONS */
15+
int steps;
16+
17+
void setup() { // WILL RUN ONCE
18+
motor.setSpeed(900);
19+
}
20+
21+
void loop() { // WILL RUN OVER AND OVER AND OVER
22+
motor.step(STEPS_PER_REVOLUTION / 2);
23+
delay(1000);
24+
motor.step(-STEPS_PER_REVOLUTION / 2);
25+
delay(1000);
26+
}

0 commit comments

Comments
 (0)