HI, as a novice i was wondering if anyone can help with coding relating to the you tube video from th elittle wicket railway, i have a basic grasp of the coding but when it comes to discussing the use of Millis with respect to multi tasking i am lost.
Can you post your code, please?
I don't really want to have to sit through a video with illegible coding.
The blink without delay example in the IDE is a good starting point to understanding simple multitasking.
There are different styles and different opinions how a code must look like to be easy to understand
This is my version. I took the Wokwi-examle code of noiasca and modified his code into a IMHO easier to understand version
... and you introduced a class with protected variables and an incorrect time comparison (">" instead of ">=") to someone who didn't understand blink without delay, and that's somehow "easy to understand"? Without waiting to see what it was s/he didn't understand?
Ah I think this is where I have gone wrong in asking, I should have said I wanted it in a slow motion movement as it will be used for a model railway turnout hence the question about multitasking. Apologies for this.
presumably the drawback of using servos is that they move at their rated speed when commanded to a new position. the obvious answer to incrementally change position with a delay between each increment and the problem with that delays prevent other operations from happening at the same time
the conventional alternative to delay() is checking millis() to perform some action after the delay period has expired instead of waiting.
but then to allow multiple actions to happen simultaneously requires tracking each possible action and sub-state of that action. a data driven approach using a table, either arrays or an array of structure is a conventional approach and making it work for one action makes it possible to work for N-actions.
each iteration of loop() sequences thru the table to do 2 things
check if a button is pressed to change the desired state of the switch, and
check if the time delay using millis() has expired and move the servo to the next incremental position
no doubt there are web pages describing all of the above separately and combining them all is the typical challenge for less experienced people