@@ -4,6 +4,12 @@ DO NOT FLASH TO TEENSY OR TO ARDUINO
4
4
5
5
*/
6
6
7
+ // test MCU kill switch
8
+ // test water interrupt
9
+ // test delay needed for thruster initialization
10
+ // test if ESCs arm after kill switches
11
+ // arm all thrusters
12
+
7
13
#include < Servo.h>
8
14
9
15
// boolean for interrupts
@@ -70,9 +76,6 @@ void updateThrusters(const uint16_t microseconds[8]) {
70
76
71
77
// attaches and arms thrusters
72
78
void initThrusters () {
73
- interrupts ();
74
- interruptFlag = false ;
75
-
76
79
thrusters[SRG_P].attach (SRG_P_PIN);
77
80
thrusters[SRG_S].attach (SRG_S_PIN);
78
81
thrusters[SWY_BW].attach (SWY_BW_PIN);
@@ -84,6 +87,8 @@ void initThrusters() {
84
87
85
88
updateThrusters (offCommand);
86
89
delay (7000 );
90
+
91
+ interruptFlag = false ;
87
92
}
88
93
89
94
void killSystem () {
@@ -96,25 +101,38 @@ void powerSystem() {
96
101
delay (100 );
97
102
}
98
103
104
+ void interruptRaised () {
105
+ interruptFlag = true ;
106
+ }
107
+
108
+ void waterInterrupt () {
109
+ if (digitalRead (WATER_DETECTED) == HIGH) {
110
+ killSystem ();
111
+ } else {
112
+ powerSystem ();
113
+ }
114
+ }
115
+
99
116
void setup () {
100
117
pinMode (SYSTEM_KILLED, INPUT_PULLUP);
101
118
pinMode (THURSTERS_KILLED, INPUT_PULLUP);
102
119
pinMode (WATER_DETECTED, INPUT_PULLUP);
103
120
104
121
pinMode (MCU_KS, OUTPUT);
105
122
106
- attachInterrupt (digitalPinToInterrupt (SYSTEM_KILLED), initThrusters, RISING);
107
- attachInterrupt (digitalPinToInterrupt (THURSTERS_KILLED), initThrusters, RISING);
108
- attachInterrupt (digitalPinToInterrupt (WATER_DETECTED), killSystem, RISING);
109
- attachInterrupt (digitalPinToInterrupt (WATER_DETECTED), powerSystem, FALLING);
123
+ attachInterrupt (digitalPinToInterrupt (SYSTEM_KILLED), interruptRaised, RISING);
124
+ attachInterrupt (digitalPinToInterrupt (THURSTERS_KILLED), interruptRaised, RISING);
125
+ attachInterrupt (digitalPinToInterrupt (WATER_DETECTED), waterInterrupt, CHANGE);
110
126
111
127
initThrusters ();
112
128
}
113
129
114
130
void loop () {
115
131
if (interruptFlag) {
116
- interruptFlag = false ;
132
+ initThrusters () ;
117
133
}
118
134
119
- updateThrusters (microseconds);
135
+ if (digitalRead (WATER_DETECTED) == LOW) {
136
+ updateThrusters (microseconds);
137
+ }
120
138
}
0 commit comments