I did a quick cross-reading of this thread. Wow lot's of things going on here.
I did not take the time to analyse everything in detail.
About the cleaning-function.
Your demo-code uses delay(). As long as the delay is executing everything else in your code is paused.
I promise you: once you have understood the concept of state-machines and non-blocking timing you never want to go back to delay()
The cleaning-process is a sequence of these steps
- Air-compressor on
- after 5 seconds air-compressor off & switching on pump
- after 5 seconds switch off pump & switch on air-compressor
- after 5 seconds switch OFF air-compressor
so a state-machine would have these states
const byte idleMode = 0; // no activity just waiting in standby
const byte airCompOn = 1;
const byte waitForCompOFF_PumpOn = 2;
const byte waitForPumpOff_CompOn = 3;
const byte waitForCompOFF = 4;
the constant names say what the state is doing.
Some time ago I have posted a thread with a demo-code that demontrate how state-machines work
If this device shall immidiately stop if some strange conditions occur and those conditions are measured by software-driven sensors you would have to get rid of each and every delay().
I did not analyse all functions that the device must do but maybe starting blinking should start immidiately and should go on continiously without a 15 seconds break while cleaning is active. For this you have to avoid each and every delay() too.
best regards Stefan