Need Help to reset the timer

Hello!

I’m currently doing my very first arduino project.
The said project is a charging station where the user can choose
which brand of phone (android/iphone). After choosing, the system
will ask if they want to use the machine with password or without password

with password==the user will put their phone inside a locker and choose a time for how long do they want to charge their phone
with out password== the user can just access the charger and press a button if they’re done

now, Im close to finishing it but I have some problems regarding with the timer. I found a timer HH:MM:SS
code on the internet, and I combine it with my code everything works fine BUT (here’s where my problem is) if the user put their password even if the seconds on timer do not reach 0 the timer do not restart.
I mean when another user chooses the same port, after the previous user is done, the timer retains its value. It should reset the moment the previous user input their correct password.

Another problem I encounter is for the lcd, I’m planning to add two more lcd so that the timer for each brand will display seperately. May I ask how do I connect additional lcds? (right now I’m using I2C bus to connect my current lcd to arduino, if somehow I add more should I just parallel the connection of the pins?)

Here’s my code for my project
P.S. I’m really sorry for my long code right now this is far as my knowledge can get me.
I attached my code because only 9000 characters is allowed

Thank you so much!

ProjectSketch_v3.0.ino (11.6 KB)

As you are using millis() for timing you never need to "reset the timer"

When a new timing period begins save the current value of millis() to an unsigned long variable then later test the elapsed time by subtracting the start time from the current value of millis().

Note the use of subtraction when calculating the elapsed time. Using subtraction and unsigned values the calculation will work correctly even when the millis() value rolls over to zero after about 49 days running of the code.

See Using millis() for timing. A beginners guide for examples of this technique.

UKHeliBob:
As you are using millis() for timing you never need to "reset the timer"

When a new timing period begins save the current value of millis() to an unsigned long variable then later test the elapsed time by subtracting the start time from the current value of millis().

Note the use of subtraction when calculating the elapsed time. Using subtraction and unsigned values the calculation will work correctly even when the millis() value rolls over to zero after about 49 days running of the code.

See Using millis() for timing. A beginners guide for examples of this technique.

THANK YOUU!!! in the end I needed to re-declare the value of mytime from the setup and set the interval back to 0 after inputting the password TYSM!!!

my problem now is to how to connect additional lcds to my arduino for separate timer display

in the end I needed to re-declare the value of mytime from the setup and set the interval back to 0

Did you fix the potential problem of not using subtraction for determining whether the required period had elapsed ?

If not then at some time this

 mytime = (millis()) + interval;

is going to cause a problem.
What will happen when mytime goes negative and you do

  if (millis() > mytime)

Whilst fixing potential problems you should consider dropping the use of Strings in favour of zero terminated char arrays (aka C strings) to avoid potential memory fragmentation issues, particularly as you change the value assigned to them several times in the program.

It would also be good practice to declare all variables with a type appropriate to the maximum value that they will ever hold.

int i = 0;
int j = 0;
int led = 13; // LED at PIN 13
int led2 = 2;
int ledState1 = LOW;
int ledState2 = LOW;
int brand1_trigger = 0;
int NO_passtrigger = 0;
int NO_passtrigger2 = 0;
int timer_trigger = 0;
int second_switch = 0;

Do any of these need to be ints or would byte be just as good ?
Some of them could also be declared const too as they never change. This too would be good programming practice.