-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrandom.ino
More file actions
29 lines (24 loc) · 749 Bytes
/
random.ino
File metadata and controls
29 lines (24 loc) · 749 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
// random example by Mike McCauley (mikem@airspayce.com)
// Make a single stepper perform random changes in speed, position and acceleration
#include <AccelStepper.h>
int DIR_PIN = 2;
int STEP_PIN = 3;
int EN_PIN = 4;
AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);
void setup() {
// Enable the stepper driver
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW);
}
void loop() {
if (stepper.distanceToGo() == 0)
{
// Random change to speed, position and acceleration
// Make sure we dont get 0 speed or accelerations
delay(1000);
stepper.moveTo(rand() % 200);
stepper.setMaxSpeed(constrain((rand() % 1500), 75, 1500));
stepper.setAcceleration(constrain((rand() % 1500), 75, 1500));
}
stepper.run();
}