Switch/Case from anywhere

Hello everybody!

I am working on a project that is using an LED to indicate the current mode. I am currently controlling the state using a case/switch block. Is there a way to use the same case/switch block to controll behavior in both the setup and loop sections, or will I need to repeat code in each section I want to access it from within?

Only if you put your switch/case in a function called by both setup() and loop().

Can you explain further why the setup() state can be delayed until loop() starts. You could use static data types within loop() and still encapsulate the data.

econjack:
Can you explain further why the setup() state can be delayed until loop() starts. You could use static data types within loop() and still encapsulate the data.

I don't understand this question - especially as you don't seem to be a newcomer.

setup() is a function that is run once when the Arduino starts and when it is finished the function loop() starts and is called repeatedly and indefinitely.

...R

KeithRB:
Only if you put your switch/case in a function called by both setup() and loop().

This is what I decided to go with. I am going to create a function that will take 2 variables, one is a status task (Update status, check status, check how long since the led toggeled ala BlinkWithoutDelay code) and the other variable is the status number (either to update to or check against, default to who cares because it is probably a blinkwithoutdelay check).

If I get a little confidance with programming this, I may upgrade the function to a library so I can just drop it into future projects.

It’s not difficult to copy a function into another program without the trouble of making a library.

…R

This sounds interesting, but I am not sure what you are trying to accomplish or why you need a switch case block to make decisions from two variables. Would it work to declare the variables statusTask and statusNumber before setup() to give them global scope, then initialize them in setup(), and then start the loop()? I like programming puzzles. Please give us more details regarding what you are trying to do. Thanks, MT.