Traffic light system Way too complex ? for a beginner (1 - 2 years)

Hello

Together with the helpers on the Dutch section of this forum I made this :

but I wonder if this not can be easily coding for a beginner ( 1 - 2 years)

The purpose of the exercise was to show an alternative approach the usual switch/case approach for state machines.

The example is far too complex for an Arduino beginner, for any definition of "beginner".

If you learned something useful from the exercise, great!

I learned statemachine's

but what I like to learn is more how to handle such a project so next time I can do it myself.

  • Please post sketches on this forum.

@LarryD I put my last sketch in my orginal question.

So no idea what sketches you want more

I'm a long way from being a beginner, I looked at that and I don't have a clue how it works!

I know how it works but only because some Dutch person who helped me , learned me this.

But still I think I miss some steps

this was the first version we build

but that one is I think not easily be extended by more traffic lights

If you asking here, it's a good practice to insert the code it this thread, not in Wokwi

oke

but then it will be a lot of small functions or one zip file

if the forum do not mind, no problem for me

So do you want a zip file of the whole code or should I paste every "module" here ?

By module do you mean file? By file that would mean tab on the IDE. How many? I'd prefer them here unless there's some daft number of them.

Perhaps also an explanation of how it works, at the moment I still don't know.

Before coding a finite state machine, your first approach should be to create finite state diagram which shows the states, the conditions which force a transition between the states and the actions to be taken on such transitions. Here is a simple example

which appeared in this thread: https://forum.arduino.cc/t/make-an-output-pin-behave-like-a-monostable-multivibrator

In the best case you can code directly from the finite state diagram.

EDIT

The solution which appears in the Wokwi linked in post #1 does seem unusually widely scattered amongst a proliferation of sub files. I tried incidentally to run it but it very quickly got stuck on yellow (amber) so it may need some tweaking.

There will be 8 tabs for all the code.

a good finite diagram will I make today or tomorrow.
I have one but that one needs to be adapted to make things clear for a outsider.

Most seem to forget the power-on bootstrap logic for the traffic lights. Hope you include it.

here is a try to make a diagram how I think the traffic light needs to work

Hopefully it is clear what I try to do

Later on I will maybe add another button and try to make a biker light work the same way as the walker lights

So is that for one car lane with a crosswalk?

Another part of communicating your intent would be, in this case, a map.

And it is very common for projects to grow, so avoid assumptions that woukd make coding, e.g., a set of crossed roads with provision for pedestrians mean starting over.

@6v6gt - I waited a time I thought was long enough and all I saw was amber.

a7

The state machine in post #9 has buttons and seems to perform reasonably based on a short test. Also your finite state diagram in post #17 has buttons. These seem to represent a single road which has the possibility for pedestrians to cross on pressing a button.
The state machine linked in post #1 had no buttons and appears also not to work so it is not clear what its relevance is to this exercise.

The next upgrade to this exercise would be a crossroads where the there is a normal traffic light sequence regulating the cars at the junction (crossroads) but with the possibility for pedestrians (and bikes) to cross and then maybe temporary priority for emergency vehicles in a specific direction.

At this moment it is a car lane with a crosswalk

Later I will add a biker lane and maybe multiple lanes.