Skip to content

Commit

Permalink
Update Watchdog.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
AFederici authored Feb 21, 2019
1 parent cc5277a commit b9d278a
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions Watchdog/Watchdog.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,54 @@ void setup() {
digitalWrite(outPin, 0);
}

void setupState1(){
changeCounter = 0;
waitPeriod = 52;
startTime = millis();
goal = 1;
state = 1;
}

void reset(){
startTime = millis();
changeCounter = 0;
}

void checkHeartBeat(){
heartBeat = digitalRead(inPin);
currTime = millis();
//check for change in hearbeat

if (heartBeat != lastBeat){ changeCounter++; }

lastBeat = heartBeat;
}


void loop() {
//START STATE
if (state == 0){
currTime = millis();
//check for change in hearbeat
heartBeat = digitalRead(inPin);
if (heartBeat != lastBeat){ changeCounter++; }

lastBeat = heartBeat;

checkHeartBeat();
//if we get 5 changes in a span of 260ms continue to healthy state
if (changeCounter > goal){
//sets everything up for the next state
changeCounter = 0;
waitPeriod = 52;
startTime = millis();
goal = 1;
state = 1;
setupState1();
}

//reset counters to continue waiting
if (currTime - startTime > waitPeriod){
startTime = millis();
changeCounter = 0;
reset();
}
}

//HEALTHY STATE
if (state == 1){
digitalWrite(outPin, 1);
heartBeat = digitalRead(inPin);
currTime = millis();
//check for change in hearbeat

if (heartBeat != lastBeat){ changeCounter++; }

lastBeat = heartBeat;

checkHeartBeat();
if (currTime - startTime >= waitPeriod){
if (changeCounter < goal){
state = 2;
}
startTime = millis();
changeCounter = 0;
reset();
}
}

Expand All @@ -78,6 +82,5 @@ void loop() {
//DO NOTHING
}
}

}

0 comments on commit b9d278a

Please sign in to comment.