-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesp_32_MouseJiggler.ino
More file actions
50 lines (38 loc) · 1.1 KB
/
Copy pathesp_32_MouseJiggler.ino
File metadata and controls
50 lines (38 loc) · 1.1 KB
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
/*
Stepper Motor Control - one revolution
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor should revolve one revolution in one direction, then
one revolution in the other direction.
Created 11 Mar. 2007
Modified 30 Nov. 2009
by Tom Igoe
*/
#include <Stepper.h>
const int stepsPerRevolution = 512; // change this to fit the number of steps per revolution
// for your motor
int randomTime = 0;
unsigned long previousMillis = 0;
int direction = 0;
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 13, 12, 15, 14);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(30);
// initialize the serial port:
Serial.begin(115200);
}
void loop()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > randomTime)
{
randomTime = getRandom(10, 100);
direction = getRandom(-1, 1);
previousMillis = currentMillis;
}
myStepper.step(direction);
}
int getRandom(int minTime, int maxTime) {
return random(minTime, maxTime + 1);
}