-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.cpp
More file actions
163 lines (126 loc) · 2.09 KB
/
control.cpp
File metadata and controls
163 lines (126 loc) · 2.09 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "mbed.h"
#define BUTTON_START p5
#define BUTTON_STOP p6
#define SWITCH_GUARD p7
#define SWITCH_TEMP p8
#define BUTTON_SHUT p13
#define LED_READY p9
#define LED_RUNNING p10
#define LED_GUARD p11
#define LED_TEMP p12
// B stands for button, s stands for switch
DigitalIn bstart(BUTTON_START);
DigitalIn bstop(BUTTON_STOP);
DigitalIn sguard(SWITCH_GUARD);
DigitalIn stemp(SWITCH_TEMP);
DigitalIn bshut(BUTTON_SHUT);
DigitalOut ready(LED_READY);
DigitalOut running(LED_RUNNING);
DigitalOut guard_on(LED_GUARD);
DigitalOut temp_high(LED_TEMP);
void Waiting(bool _isStart);
void Running(bool _isStart);
void Pause(bool _isStart);
void Shut(bool _isStart);
int main()
{
Waiting(false);
}
void Waiting(bool _isStart)
{
while(_isStart == false)
{
if (sguard && !stemp)
{
ready = 0;
running = 0;
guard_on = 1;
temp_high = 0;
}
if (!sguard && stemp)
{
ready = 0;
running = 0;
guard_on = 0;
temp_high = 1;
}
if (sguard && stemp)
{
ready = 0;
running = 0;
guard_on = 1;
temp_high = 1;
}
if (!sguard && !stemp)
{
ready = 1;
running = 0;
guard_on = 0;
temp_high = 0;
}
wait(0.25);
if (bstart && (!sguard && !stemp))
{
_isStart = true;
break;
}
else
continue;
}
Running(_isStart);
}
void Running(bool _isStart)
{
while (_isStart == true)
{
running = 1;
guard_on = 0;
temp_high = 0;
ready = 0;
wait(0.25);
ready = 1;
wait(0.10);
if (bstop || stemp || sguard || bshut)
{
_isStart = false;
break;
}
}
bshut ? Shut(_isStart) : Pause(_isStart);
}
void Pause(bool _isStart)
{
while (_isStart == false)
{
ready = 1;
running = 0;
temp_high = 0;
guard_on = 0;
if(stemp)
{
ready = 0;
running = 0;
temp_high = 1;
sguard ? guard_on = 1 : guard_on = 0;
}
if (sguard)
{
ready = 0;
running = 0;
stemp ? temp_high = 1 : temp_high = 0;
guard_on = 1;
}
if (!bstop && !sguard && !stemp)
{
_isStart = 1;
break;
}
wait (0.25);
}
Running(_isStart);
}
void Shut(bool _isStart)
{
if (_isStart == false)
main();
}