For what you call your 2nd and 3rd step in your project there is only one step to learn
learning how state-machines work
all in all you have more than two conditions. Whenever you have more than two conditions that make up sequences
a good way to write code for such sequences is to use a state-machine
Your process is
set reference weight
-
if any weight is on the scale
check if a button is pressed for 5 seconds which means take a snapshot of time and -
measure how much time goes by while the button is pressed down
-
when button is pressed down for more than 5 seconds use this weight as reference weight
and show message on display
operation after defining reference-weight
-
check if reference-weight is on the scale
if a different weight is measured make a snapshot of time -
and measure how much time goes by while weight is different
if more than one minute has passed by -
switch on LED
if more than two minutes have passed by make snapshot of time and -
turn on buzzer
check if more than 1 minute has passed by since buzzer was switched on
if more than 1 minute have passed by switch buzzer of
all in all 7 different things. You could say 7 different states.
You can code this by using many many if-elseif-elseifelseifelseif-elses
creating a big mess where to set which flag-variable true or false
Or you learn how state-machines work and once you have learned it
you never will go back to if-elseif-elseif-elseif-
The state-machine will be very easy to modify and very easy to maintain
once you have understood the basic principle.
You have avoided to already use a state-machine.
I really recommend that you are learning it
best regards Stefan