Hi,
Interesting project.
This line here appears it may not be doing what you expect:
analogRead(genHV);
** if (genHV, HIGH) {**
In the analogRead() genHV refers correctly to the A0 pin being tested, but in the next line the pin number (still A0) is used again rather than the value of the reading on that pin. Were you looking perhaps to test if the genHV pin was above a certain value? That would look something like this:
if(analogRead(genHV)>= somespecifiedvalue) {
Since each of the 3 attempts to start the generator are the same, rather than having 3 functions defined which are essentially the same, you could simplify this into one function, Estart() and call that as many times as you need, up to 3 as you have here for example. This can be done with a loop structure. Something like this perhaps:
// in loop()
if (voltage <= batL); {
for (int tryCount = 0; tryCount < 3 && analogRead(genHV) < somespecifiedvalue; tryCount++) {
Estart();
}
if(analogRead(genHV) < somespecifiedvalue) { // generator didn't start after 3 tries
// do the error stuff presently in try3
} else {
digitalWrite(genok, true);
}
Remember to add the test and function call for shutdowngen() to loop() now as Try2 and try3 functions would no longer be present.
Estart would then be simplified to
void Estart () {
digitalWrite (solPin, HIGH);
analogWrite(genstart, 50);
delay (1000);
digitalWrite(genstart, HIGH);
delay (500);
digitalWrite (solPin, LOW);
digitalWrite (genstart, LOW);
delay (500);
}
The loop part of the code repeats infinitely, so anything that needs to be monitored can be placed in there, and the functions called for the generator to be started and stopped as required.
Structuring it so all the repeated tests are in loop() also means you won't need to call another function at the end of each of your functions...when they conclude control will return to loop() which will make the code easier to follow and debug.
Hope this is useful to you. All the best with your project,
Geoff