-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMotorAnlysis.ino
50 lines (38 loc) · 1.06 KB
/
MotorAnlysis.ino
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
// Press a button to restart and continue logging
// Run for 10 seconds and collect data, printing it to the serial output, then reset
// When 10 seconds are up, stop logging and turn on the LED
// When button pushed, do the same thing again
const int BUTTON = 2;
const int HALL = 3;
const int LED = 4;
double pos = 0.0; // Angular position of the motor in radians
double last = 0.0; // last time stamp
double zero_time = -1.0;
void setup() {
pinMode(HALL, INPUT);
pinMode(BUTTON, INPUT);
pinMode(LED, OUTPUT);
attachInterrupt(digitalPinToInterrupt(HALL), hall_ISR, CHANGE);
attachInterrupt(digitalPinToInterrupt(BUTTON), button_trig, HIGH);
Serial.begin(9600);
zero_time = millis();
}
void loop() {
double t = millis() - zero_time;
if (t < 10000 && t != last) {
String output = (String) t + "," + pos;
Serial.println(output);
digitalWrite(LED, LOW);
}
else {
digitalWrite(LED, HIGH);
}
last = t;
}
void hall_ISR() {
pos += PI; // For the side magnet bar configuration
}
void button_trig() {
zero_time = millis();
pos = 0.0;
}