I have read your comments and I want to thank you for replying on such short notice. In your sketch when Lampon == 1 the states are going in chronological order. 0 -> 1->2 etc. And when Lampon == 0, the program stops and start again at state 0. But for my purpose, I want to stop the program when the time in state is working and I want to let it continue where it was stopped.
But that is not possible.
So I wil use an interrupt pin, at least I can turn the relays on and off.
BTW: This is a code for 1 of the four slaves I have. The masters gets input from pushbuttons and it sends different data to the slaves. 1 of the slaves is 50 meters away from the master. That is pretty cool, because I2C bus is not made for that length.
Can you please explain what that means it is very unclear when exactly you want to stop and start.
Once you can tell us that it is simple to pause the advancement of the states, and resume it.
No no no no no. Do not think about using an interrupt if you insist on this then you are on your own.
Not cool but a bit stupid. Have you looked at the signal at the far end in an oscilloscope? And how can you be sure it is working or not. Remember just because something appears to function doesn't mean it is a good reliable circuit.
If you want to communicate over a long distance reliably you need to use a differential buffer at both ends. Like one of these
Yea I got a buffer like that, I think it is still pretty cool that i2c bus can work such longe range. I tested with an oscilloscope and it is reliable.
The idea is that when a relay is active for example 4 sec, the roller shutter is opening. BUT I want to be able to ''pauze or freeze'' the relay with a button and with the same button it need to "continue of unfreeze" the relay, where it paused.
And I think that with a state machine, it wont work.
Then, as an intern, it is up to you to find an alternative. Internship is an introduction to a job that normally requires independent research and problem solving.
Failing that, an ability to fairly evaluate and process advice from your colleagues.
I still don't know what this means.
Let's say the shutter has been opening for one second. Do you want the roller to stop moving on a button press. Which means making the relay that controls the motor should open. And then when that button is is pressed again start the motor moving for the remaining time of the delay?
Is this a one off during a state or can it happen many times?
There is no problem doing that with the state machine I drew, it is just the code inside those states must be written to accommodate this change of the button by working out the time left to run until the state ends. Then when the action is resumed using that time left to work out a new target time and resuming the normal operation of timing.
FreeRTOS looks like it's got more to memorize than it takes to learn basic nonblocking code except for those with too many years writing DP code... the poor souls.
Get rid of that way of thinking! You don't stop a program! You let it run! Stopping a program is when you cut power from your Arduino.
When your Arduino tells your roller shutters to roll, your Arduino program is running. When your Arduino tells your roller shutters to stop, your Arduino program is still running. While the roller shutters are in stationary position, your Arduino program is still running. You just have to decide what the program is doing at each moment. But it is not stopping until you pull the power chords.
When you start thinking in this way, you're ready to consider the state machine concept.
And further to my post #26, what has priority when the push button has frozen the normal sequence timing?
Is it a change in the value of Lampon or the unfreezing of the program advance timing?
Have you even thought about that?
There is almost nothing better suited to create such functionalities as with state-machines.
I want to explain why:
A state-machine is a function that is entered and leaved thousands of times per second
jump_in / jump_out.
Keep executing the same "state" until a new "state" is set by whatever
So there is a state for "move" and a state for "pause" combined with non-blocking timing this is perfectly suited for functionalities like you have described.
start a movement
stop this movement through a press of a button (the button-press just switches the state from "moving" to "pausing")
if in paused mode the press of the exact same button starts the "resuming"
including calculating a new time for beeing on
and then you can repeat this as often as you want.
This way of programming is
completely different
from sequential programming
do step 1
delay()
do step 2
delay()
You have to grasp this new basic concept of
jump_in / jump_out
first and then go on with code-developping