-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganizing code
83 lines (35 loc) · 877 Bytes
/
organizing code
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
enum state {CALIBRATING, MOVING_UP, MOVING_DOWN, WAITING };
void stateMachine_setup()
{}
Serial.begin(9600);
pinMode(limitSwitchPin,INPUT_PULLUP);
pinMode(limitSwitchPin2,INPUT_PULLUP);
pinMode(MOTOR_IN1, OUTPUT);
pinMode(MOTOR_IN2, OUTPUT);
Serial.println("Encoder Final Test:");
state = CALIBRATING;
}
void stateMachine_loop()
{
// get inputs
get_encoder_inputs();
get_limit_switch_inputs();
// logic goes here
encoder_logic();
limit_switch_logic();
// do outputs
if (state == CALIBRATING)
{
// do calibration movement
}
else if (state == MOVING_FORWARD)
{
// do forward moves
}
else if (state == MOVING_BACKWARD)
{
// do reverse moves
}
else if (state = WAITING)
{
// do the waiting, don't use delays