-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpirduino.ino
131 lines (94 loc) · 2.61 KB
/
pirduino.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
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
#include <OneWire.h>
void setup() {
buzzStartWork();
//start serial connection
Serial.begin(9600);
initPinOutput();
clearPowerOutput();
setupAnalogandIdle();
delay(400);
buzzSignalStop();
firstPowerTest();
}
void firstPowerTest(){
Serial.println(F("start first test"));
clearPowerOutput();
delay(50);
_checkExceptionPowerVoltage();
tabletOn(true);
cameraOn(true);
delay(1000);
highLightOn(true);
delay(1000);
fanOn(true);
delay(5000);
_checkExceptionPowerVoltage();
cameraOn(false);
fanOn(false);
delay(500);
highLightOn(false);
delay(20);
_checkExceptionPowerVoltage();
Serial.println(F("first test done!"));
}
static const unsigned int TIMEOUT_MS_FAN_OFF = 10000;
static const unsigned long TIMEOUT_CAPTURE_OFF = 60000;
void loop(){
tabletOn(true);
Serial.println(F("listen START signal:"));
// the program first polls the motion sensors to gather information about the presence of humans in the area
while(seriouslyCheckStartSignaledSensor() == false){
if(_checkExceptionPowerVoltage()) return; // check arduino's power
delay(1);
if(_checkTemperature(20*1000)) return; // check pirduino's temp
}
Serial.println(F("Turn On all:"));
fanOnPiLoop(true); // turn on the fan
highLightOn(true);
buzzSignalStart();
delay(50);
buzzSignalStop();
cameraOn(true);
delay(5000);
Serial.println(F("listen STOP signal:"));
while(seriouslyCheckStopSignaledSensor() == false){
if(_checkExceptionPowerVoltage()) return;
delay(10);
if(_checkTemperature(1000)) return;
waitRestartCamera();
}
buzzSignalStop();
delay(50);
buzzSignalStop();
Serial.println(F("hold on 100 seconds. Wait new gamer. If they do, we can get back to playing the game as fast as possible. There's no need to restart the system."));
const unsigned long end_time_wait = millis() + TIMEOUT_CAPTURE_OFF;
while(end_time_wait > millis()){
if(_checkExceptionPowerVoltage()) return;
delay(10);
if(_checkTemperature(1000)) return;
waitRestartCamera();
if(seriouslyCheckStartSignaledSensor()){
Serial.println(F("find starting signal, goto start of the loop"));
return;
}
}
Serial.println(F("No new gamer. Turn Off cam and highLight(LED):"));
cameraOn(false);
highLightOn(false);
Serial.print(F("FAN works 10 seconds for cooling"));
int mi = 0;
for( ; mi < TIMEOUT_MS_FAN_OFF; mi++){
delay(10);
if(seriouslyCheckStartSignaledSensor()){
Serial.println(F("PreFan started"));
break;
}
if(_checkExceptionPowerVoltage()) return;
}
Serial.print(F("TIMEOUT FAN end: "));
Serial.println(mi);
if(mi >= TIMEOUT_MS_FAN_OFF){
Serial.println(F("Fan Off"));
fanOnPiLoop(false);
}
}