Arduino 24h timer with set/reset buttons

Hello guys i'm new in the arduino world but i already have big projects in mind! I'm building a simple automatic hay feeder for my horses, it's basically something like this but with just 2 floors,

Every 24hrs (at 6am) a servo should make the plate in the middle fall and the hay should fall down, the problem i have is with the timer, it' should be a very simple interface with 3 buttons a green button to start the timer when pressed, a red button to reset the timer and a blue button to eventually reset the servo to lock the plate again , but i'm struggling with the timer right now

const int greenB = 2; 
const int redB = 3;        

int inAction = 0;
int greenState = 0;
int redState = 0;         
void setup() {

Serial.begin(9600);
pinMode(greenB, INPUT);
pinMode(redB, INPUT);
}

void loop() {

  greenState = digitalRead(greenB);
  redState = digitalRead(redB);

  if(greenState == HIGH){
    inAction = 1;
    while(inAction == 1){
      for(int i = 0; i<10;i++){
        if(i == 10){
          Serial.println("Cycle completed");
        }
         if(redState == HIGH){
          Serial.println("timer stopped");
          goto stopTimer;        
        }
        Serial.println("10 seconds timer");
        delay(1000);  
      }
      stopTimer: Serial.println("timer stopped");inAction = 0; 
      
    }
  }
}

What it should do is to start the timer the moment i pressed it and do the cycle every 24hrs (i put 10 seconds now to test it) when i press the green button it starts but it sops after 10 seconds and it should stop only when i press the red button...what am i doing wrong?

here is the console

consider

// hayfeeder controller

#if 0
const byte GreenB = 2;
const byte RedB   = 3;
#else
const byte GreenB = A1;     // button
const byte RedB   = A2;     // button
#endif

#define ON  LOW
#define OFF HIGH

const byte ServoL = 10;     // led
const byte HourL  = 11;     // led

enum { Stop, Run };
int state =  Stop;

char s [100];

// -----------------------------------------------------------------------------
#define PERIOD  20

unsigned int  hour   = 1;
unsigned int  minute = 0;

void timer (void)
{
    static unsigned long msecLst  = 0;
           unsigned long msec     = millis ();

    if (msec - msecLst > PERIOD)  {
        msecLst = msec;

        if (60 <= ++minute)  {
            minute = 0;
            if (24 <= ++hour)
                hour = 1;
        }
        sprintf (s, "%s: %2d:%02d", __func__, hour, minute);
        Serial.println (s);
    }
}

// -------------------------------------
void timerReset (void)
{
    Serial.println (__func__);
    hour   = 1;
    minute = 0;
}

// -----------------------------------------------------------------------------
void loop (void)
{
    if (LOW == digitalRead (GreenB))  {
        if (Stop == state)
            Serial.println ("Run");
        state = Run;
    }

    if (LOW == digitalRead (RedB))
        timerReset ();

    if (Stop == state)
        return;

    // ----------------------------
    // if Run
    timer ();

#define AlarmHour   6
#define AlarmMinute 0

    if (AlarmHour == hour && AlarmMinute == minute)
        digitalWrite (ServoL, ON);          // dump hay
    else
        digitalWrite (ServoL, OFF);         // close

    digitalWrite (HourL, 0 == minute ? ON : OFF);

}

// -----------------------------------------------------------------------------
void setup() {
    Serial.begin(115200);

    pinMode      (GreenB, INPUT_PULLUP);
    pinMode      (RedB,   INPUT_PULLUP);

    digitalWrite (ServoL, OFF);
    pinMode      (ServoL, OUTPUT);

    digitalWrite (HourL, OFF);
    pinMode      (HourL, OUTPUT);
}

gcjr:
consider

// hayfeeder controller

#if 0
const byte GreenB = 2;
const byte RedB  = 3;
#else
const byte GreenB = A1;    // button
const byte RedB  = A2;    // button
#endif

#define ON  LOW
#define OFF HIGH

const byte ServoL = 10;    // led
const byte HourL  = 11;    // led

enum { Stop, Run };
int state =  Stop;

char s [100];

// -----------------------------------------------------------------------------
#define PERIOD  20

unsigned int  hour  = 1;
unsigned int  minute = 0;

void timer (void)
{
    static unsigned long msecLst  = 0;
          unsigned long msec    = millis ();

if (msec - msecLst > PERIOD)  {
        msecLst = msec;

if (60 <= ++minute)  {
            minute = 0;
            if (24 <= ++hour)
                hour = 1;
        }
        sprintf (s, "%s: %2d:%02d", func, hour, minute);
        Serial.println (s);
    }
}

// -------------------------------------
void timerReset (void)
{
    Serial.println (func);
    hour  = 1;
    minute = 0;
}

// -----------------------------------------------------------------------------
void loop (void)
{
    if (LOW == digitalRead (GreenB))  {
        if (Stop == state)
            Serial.println ("Run");
        state = Run;
    }

if (LOW == digitalRead (RedB))
        timerReset ();

if (Stop == state)
        return;

// ----------------------------
    // if Run
    timer ();

#define AlarmHour  6
#define AlarmMinute 0

if (AlarmHour == hour && AlarmMinute == minute)
        digitalWrite (ServoL, ON);          // dump hay
    else
        digitalWrite (ServoL, OFF);        // close

digitalWrite (HourL, 0 == minute ? ON : OFF);

}

// -----------------------------------------------------------------------------
void setup() {
    Serial.begin(115200);

pinMode      (GreenB, INPUT_PULLUP);
    pinMode      (RedB,  INPUT_PULLUP);

digitalWrite (ServoL, OFF);
    pinMode      (ServoL, OUTPUT);

digitalWrite (HourL, OFF);
    pinMode      (HourL, OUTPUT);
}

Ty this seem to work but it's a bit to complex for me to understand yet xD i'd like a more simple/"dumb" way to do it

Sry double post but i think i found a simple solution

#include <Servo.h>
Servo hay;
int pos = 0;
const int greenB = 2; 
const int redB = 3;        
int inAction = 0;
int greenState = 0;
int redState = 0; 

 #define gTimer 6
 #define redT 7     
      
void setup() {
hay.attach(9);
hay.write(0);
pinMode(gTimer, OUTPUT); 
pinMode(redT, OUTPUT); 
Serial.begin(9600);
pinMode(greenB, INPUT);
pinMode(redB, INPUT);
}

void timetoEat(){
   for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    hay.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15); 
}
hay.write(0);
}

void loop() {

  greenState = digitalRead(greenB);
  redState = digitalRead(redB);

  if(redState == HIGH){
    inAction = 1;
    digitalWrite(redT, LOW);
    while(inAction == 1){
      
      for(long i = 0; i<10;i++){
        Serial.println(i);
         digitalWrite(gTimer, HIGH); 
        delay(1000);
          
        greenState = digitalRead(greenB);
        if(greenState == HIGH){
          Serial.println("timer stopped");
          inAction = 0;
          digitalWrite(gTimer, LOW); 
          digitalWrite(redT, HIGH);
          break;      
        }
        if(i == 9){
          timetoEat();
          Serial.println("Cycle completed");
        }  
        digitalWrite(gTimer, LOW);  
      }   
      
    }
    
  }
}

basically i forgot to read the state of the red button in the for and for resons i don't know yet the goto wasn't doing what i was thinking it was going to do.... now i just need to add a long insted of an int to the for so i can count to 86400 (seconds in 24hrs) and it should do the job unless i'm missing something

yasulander:
Every 24hrs (at 6am) a servo should make the plate in the middle fall and the hay should fall down

green button to start the timer when pressed
red button to reset the timer and
blue button to eventually reset the servo to lock the plate again
but i'm struggling with the timer right now

all your nested control makes it hard for me to understand your code. i tried un-nesting the code so everything can run independent of one another.

am i correct that the button switches are momentary?
am i correct that the input is LOW when pressed?
am i correct that when you say reset the timer, you mean set it to zero but allow it to continue to run?
am i correct the when you say start the timer you mean open the plate when 6am is reached?

i used a state variable as a flag conditionally execute the code that runs and checks the timer to drop and close the plate. you said the green button starts the timer but not how it stops it.

the red button simply resets the timer as I describe above. not sure how that is suppose to work if you want the plate to open at 6am. shouldn't it set the timer to the current time?