Timers and output delays help

Hello,

I'm sorry if I might be of trouble but I'm fairly new with Arduino. I hope you can help me with this for I've tried google on ideas but it seems not what I'm trying to implement. I have a project my professor gave me that goes like this:

An Led lights up 10 seconds after a 'start' push button is pressed. Another button called the 'stop' push button turns off the Led 15 seconds after it was pressed. A timer is used to track the total 'ON' time of the Led and when it reaches 3 minutes another indicator led lights up and a 'reset' push button is pressed to reset the process. The times also should also be displayed in an LCD.

So, overall there are 3 push buttons 'Start' , 'Stop' , 'Reset'.
and 2 Leds to indicate the process and an LCD to display the running time.

I'm mostly confused on starting a count up timer when the push button is pressed and
tracking the total 'ON' time state of the Led output.

Hope you can help me with this. Thank You!

Clearly as it is school work, it is best if you solve this yourself together with your professor. Just to get you started, you could use code like this for the first part.

unsigned long startButtonPushedAtMs ;
bool inStartPhase = false ; 

. . . 

loop() {
. . . 

   if ( startButtonPushedDetected ) {
      startButtonPushedAtMs = millis()  ;  // start timer startButtonPushedAtMs
      inStartPhase = true ;
   }
   . . .
   . . .
   if ( millis() - startButtonPushedAtMs > 10000UL && inStartPhase == true ) {
      digitalWrite( ledPin , HIGH ) ;  // switch led on 10 seconds after start button push
      inStartPhase = false ;
   }
. . .
}

You'll need several time variables - millis() will be accurate enough for this as counter.

One that keeps track of when the ON button is pressed (as 10 seconds later the LED has to go on).
One that keeps track of when the OFF button is pressed (as 15 seconds later the LED has to go off).
One that keeps track of the total ON time.

Now if the ON button is pressed, and immediately after the OFF button, is the LED supposed to remain on (ignoring the OFF button press when the LED is off), or should the LED switch off after being on for just over 5 seconds, i.e. 15 seconds after the OFF button was pressed?

If the ON button is pressed a second time while the LED is still off, reset the timer or continue counting?

First of all, you should draw a flowchart of your program, then understand how works a finite state machine (FSM) . See e.g. this tutorial (Google translate is your firend):

http://forum.arduino.cc/index.php?topic=470879.0

Likewise look for a tutorial on Timer Counter programming.

Thanks for everyone's suggestions! I've asked my professor about this and he says to use the for-loop to act as count up/down timer to time the on and off state of the LED.

Here's my code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int buttonPin[] = {7,8,9};
const int ledPin = 13;

int buttonState = 0;


void setup() {
 
  for (int x = 0; x < 2; x++){
  pinMode(ledPin, OUTPUT);
  }
  for (int x = 0; x < 3; x++) {
    pinMode (buttonPin[x], INPUT);
  }
  lcd.begin(16, 2);
}
void loop() {
  
  for (int x = 0; x < 3; x++)
  {
    buttonState = digitalRead(buttonPin[x]);
    
    if (buttonState == HIGH && buttonPin[x] == 8) {
    for(int s = 1; s <= 10; s++)
    {
      lcd.print(s);
      delay(1000);
      lcd.clear();
    }
    digitalWrite(13, HIGH);
  }
  if (buttonState == HIGH && buttonPin[x] == 9){
  for(int s = 15; s>0; s--)
    {
      lcd.print(s); 
      delay(1000); 
      lcd.clear();
    }
    digitalWrite(13, LOW);
  }
  }
}

Now I only need to keep track on the 'ON' time of the LED. When the LED is 'ON' it counts the time and pauses it when LED is 'OFF' state.

I've tried this simple line of code to just check if it'll count when the LED is ON, I placed it on the last line of the code above but it doesn't print anything on the LCD.

if (digitalRead(ledPin) == HIGH){
  for (int s = 0; s < 0; s++ )
  {
    lcd.print(s);
    delay(1000);
    }
  }

How can I proceed about this?

Whatever you intended I'm pretty sure that last for loop isn't doing it.

Steve