Hi robin
i have edited the code slightly by taking the currentWash++ and placing it inside the
if(reading == 1 && motorRunning == true )
statement as it would not increment.
Hopefully the following make sense.
If reading = 0 then the switch has made so the motor needs to be turned off as the wash jet is aligned. It can now turn the wash pump on. stopTime records the time this happened and motorRunning made TRUE so this is not run again. Wash pump is left ON at this point
if(reading == 0 && motorRunning == false){ // switch closed so stop motor and start wash
digitalWrite(selectorMotor, HIGH); // OFF
stopTime = millis();
motorRunning = true;
digitalWrite(washPump, LOW); //ON
Serial.println("Wash ON / Motor OFF");
}
After a set time the jet selector motor is turned on so the cam can get away from the micro switch and open the switch.
if (millis() - stopTime >= washDuration && motorRunning == true){
digitalWrite(selectorMotor, LOW); //ON
}
Now motor is running and motorRunning = TRUE i am waiting for the the switch to open, the jet will have moved half way from the pump so I need to turn off the wash pump change motorRunning to false but keep the selector motor running so it can move around to the next position to make the switch again.
if(reading == 1 && motorRunning == true ){ // switch open so motor should be running
motorRunning = false;
digitalWrite(selectorMotor, LOW); //ON
digitalWrite(washPump, HIGH); //OFF
currentWash++;
}
This will then happen all over again.
The last piece should reset currentWash to 0 for the next time i call this function.
if (currentWash == 3){
flag++;
Serial.println(currentWash);
currentWash = 0;
Serial.println(currentWash);
}
This is working in simulator but i do need to test it in real tonight. It has been a pain to write due to the fact the selector motor need to run for a few second to open the cam switch.