Hello to all,
I need some help for a rather simple project, with a twist.
My knowledge on programming is very low, as you will understand but I 'm trying to learn and get better project by project..
The project is very simple. It is a 4 stage program with 2 minutes duration.
In a simplified overview:
STEP1: 59,5 sec waiting time
STEP2: 0.5 sec output 1 ON
STEP3: 59 sec waiting time
STEP4: 1 sec output 2 ON & 0.5 Sec output 1 ON.
This is a very simple thing to create.
But.......
I need to have one Button input, to by-pass the waiting times in steps 1 & 3, when the button is pressed.
If the button is pressed during waiting time 1, the program must jump to sec 58 and
If the button is pressed during waiting time 2, the program must jump to sec 118.
Which function/logic shall I use to create this?
Have a look at how to make a state machine. There are loads of examples, but you may find this one and/or this one a good place to start.
Kudos on the nice diagram which makes it pretty clear. BUT it highlights one thing: the first wait goes to t=59.5 yet you say if the button is pressed during that period it should jump to t=58. Thing is, it could be between t=58 and t=59.5 already, so should it go back to t=58 or what?
edit: not that, as @kolaha points out, you can make a time machine. To "jump" from say 10s to 58s you would need to cancel the current timing and have a new timer that only lasts 2s.
As for the timings, I don't need that accuracy. 58 was written as an example.
It is a simple timer, which I need to eliminate the waiting time to go to the next step.
So, the "GOTO" can lead to the next step, or at sec 59.4 (in the first stage and 118.9sec in the second one).
I don't know about the time machine, although the name sounds interesting!
The button input can be energized anytime in the program. It should be ignored, during step 2 and 4.
I 've checked the program yesterday and came to these results:
At the beginning there was an error message about time1 and time2
as they were "not declared in this scope".
So I copy-paste the two lines:
and declared them as uint32_t
after the line uint32_t Timer = 0
This fixed the problem
Then there was a ";" missing from a line, and the program is working!
I will upload the working code in a next message, so we can have the final result, but check my uint declarations first