1

When I try to run my code so far with the menu and select buttons, it seems that it works, except that the main menu will not move past "Main Garden" to "Currants". There's also a problem with the submenu where after the first watering warning, pressing the select button makes it simply return to the main menu without lighting the LED on the LEDPower pin or running that watering routing for the whole watering interval.

The one guess I still haven't tried is that maybe I should change void MainMenu() to a Switch Case structure instead of If-Else?

.

edit:

.
0

1 Answer 1

1

Problem One (Menu not moving past Main Garden to Currants):

MainOld is used to increment MenuState but MainOld never gets incremented, which means it will never have a value greater than 0. Accordingly MenuState can never be greater than 0 + 1.

Problem Two (Sub Menu looping back to main):

'Checking' the state of LEDPower like in Water1() is not the best way to accomplish what you want to accomplish. It may work but is not technically correct as LEDPower is a pin state and you never actually read the state.

The other issue in Water1 is that previousWaterMillis doesn't get updated anywhere in your code, which means that anytime Water1 is called more than 10 seconds after boot your solenoid will activate and then immediately deactivate. I would recommend a while loop inside your Water1 function. ex.

void Water1(){
  digitalWrite(Relay1, HIGH);
  unsigned long currentMillis = millis();
  previousWaterMillis = millis();
  int LEDPowerState = digitalRead(LEDPower);

  while(currentMillis - previousWaterMillis <= WateringInterval){
    digitalWrite(LEDPower, HIGH);
    Serial.println("Watering Garden with LED Lit");
    currentMillis = millis();
  }
  
  digitalWrite(Relay1, LOW);
  digitalWrite(LEDPower, LOW);
  SubMenuState = 0;
  SubMenuOld = 0;
}

^^ This will illuminate your LED and activate the solenoid for the 10 secs you wish to water. 
1
  • 1
    Thank you so much!! I added MainOld = MenuState; to menubuttoncheck() to make MainOld increase with the presses, did void Water1 as you said, and it works! Dec 29, 2020 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.