Multiple tabs statemachines

Hello everyone,

Im learning to work with arduino/C in school, im enjoying it very much but im still kinda new.

Now for our final project, we have to make something that requires multiple statemachines. Now i run into the following problem:

For every statemachine i want to make a Tab, but in the statemachines things get triggered by states of other statemachines. If i try to check (for example) Trafficlight1_State = TRAFFICLIGHT1_STATE_STOP, i get the message 'TRAFFICLIGHT1_STATE_STOP' Declared out of scope. This is because it is in a tab to the right.

For some reason arduino's compiler can't see tabs to the right. As statemachines in my program are quite dependant on eachother, its not possible to make one order that solves all the compiling problems.

What options do i have to solve this?

One possibility i thought of, was declaring the different states of the statemachines in 1 big tab at the start. This would be quite ugly though, and not very structured.

Any suggestions?


Two options that you can try (not tested)

Declare thinks like TRAFFICLIGHT1_STATE_STOP in the main sketch
Create an include file that contains TRAFFICLIGHT1_STATE_STOP (and others) and include that in the main sketch.

I assume that you're using multiple ino files and not multiple cpp files.

Hey thanks for the reply.

Including all (in total probably 20 states, over 5 different components) in the main sketch would be a bit ugly im think. My teacher is gonna rate me for this project, so code should look well structured etc. Thats why i'd prefer the states to be there just above the statemachine diagram.

The include file might be my best option. Never created and included one, is it complicated?


What are the names of the files that appear on the tabs ?

The names are the names i gave them, .ino

Creating an include file works the same way you created your other tabs. Just give the file the extension .h.

Include that file in the main sketch using #include "yourHfile.h".

Example, your file is called stateconstants.h


Replace the dots by your stuff. You nred to read up on include guards to understand the construction used around the dots.