im just begun with the you tube course of Paul McWorther.
The first challenge is to make some code that a led blinks 5 times. another one 10 times and another one 15 times.
Now I also read about a state machine.
Could the challenge be solved with a state machine or can I better use three for loops to make this work.
You could program it using a state machine but unless the sketch is required to do something else whilst the LEDs blink, such as reading an input, I would not bother
Three for loops running one after the other would work, as would a single function called from loop() with parameters defining which LED to blink and the number of times to blink
Look forward to doing many things different to how Paul McWhirter does as he runs you through the basics.
But do follow along slavishly if you can tolerate him. If you jump past a few dumb or less than perfect ways to do things, you will have missed an opportunity to let it all soak in.
Sometimes the best way to see a new method of doing things is from the perspective of having done things a few times or more using only simple logic and code.
It's easy to think you mastered something like the if/else statement or while loops or even "blink without delay" only to find yourself looking at code you can't even begin to read, let alone make any sense of, let alone letting alone writing anything that does something similar.
usually you define the state of a coherent system.
as OP explained this
there does not seem any relationship between the leds, so you could consider there are 3 independent systems and if you can solve the issue for one system with some parameters, then you just need to instantiate the other two with other parameters
in the example of post 3 of Flashing multiple LEDs at the same time I took that approach, once the class was defined, it was just a matter of instantiating the LEDs
and the loop was pretty trivial, just ticking the state machine.
here it's roughly the same approach but you need to add one parameter which is the number of flashes.
not sure what this means. state machines typically have sub-states and its not uncommon for a single rather than multiple state machines. Or would a coherent state machine not have any sub-states (e.g. on/off state of LED within a machine that tracks which LED is toggling)
a single state machine would handle all states and all simuli, i'm thinking of a matrix. A single state machine would have cases where many stimuli have not effect in many states
I meant it depends on how you define "the system" for which you describe the states.
It could be one system with the three leds and then they could have 8 states (if 0 is OFF and 1 is ON ➜ 000, 001, 010, 011, 100, 101, 110, 111) and there is only one FSM
it could be 3 independent systems, each with its own FSM.
the class example I gave before is for the latter.
First I want to try to make them run one after each other. Maybe later blink concurently.
I think all led's are the same with time. so onTime 500ms and offTime also 500ms to begin with.