Update RC_Excavator_RX.ino and timer.h

This commit is contained in:
mxcory
2024-12-12 15:06:34 -05:00
parent 8a79e5cae7
commit 06793b9087
2 changed files with 25 additions and 18 deletions
+18 -15
View File
@@ -83,6 +83,7 @@ void setup() {
void loop() {
// This device is a RX node
@@ -102,6 +103,7 @@ void loop() {
Serial.print(payload.message); // print outgoing message
timerReset(0); //Reset watchdog timer
Serial.println();
@@ -125,26 +127,27 @@ void loop() {
RX_CHANNELS [i] [_VAL] = TEMP_RX[i];
}
if (safetyCheck()) { //If safety check passed, allow outputs
channelOutput(1);
channelOutput(2);
} else {
for (int i=1;i<NUM_CHANNELS; i++) { //Else disable outputs
analogWrite( RX_CHANNELS[i] [_PIN], 0);
analogWrite( RX_CHANNELS[i] [_PIN2], 0);
Serial.println("Watchdog Failed!");
}
}
//Force output to channel 2
// load the payload for the first received transmission on pipe 0
radio.writeAckPayload(1, &payload, sizeof(payload));
}
}
if (safetyCheck()) { //If safety check passed, allow outputs
channelOutput(1);
channelOutput(2);
} else {
for (int i=1;i<NUM_CHANNELS; i++) { //Else disable outputs
analogWrite( RX_CHANNELS[i] [_PIN], 0);
analogWrite( RX_CHANNELS[i] [_PIN2], 0);
}
}
} // loop
+7 -3
View File
@@ -31,16 +31,20 @@ void timerSetup() {
//Use this to check if set time has passed.
//Will return true or false
bool timer(unsigned long _interval,int _id, bool _reset = true) { //_interval in millis, _id in countData
bool _return = false;
if (millisCount(1,_id) >= _interval) {
if (_reset) { //If true, reset timer after tripping
millisCount(0,_id);
}
return true;
} else {
return false;
_return = true;
}
return _return;
}
void timerReset(byte _id) { //Reset timer start time
countData[_id]= millis();
Serial.print("Timer Reset: ");
Serial.println(_id);
}