Are the variables declared in such blocks only allocated upon hitting the block
Yes.
An example is a section which takes commands from bluetooth, but would rarely get a command to set the time, or to manually turn on a sprinkler.
I can't imagine why local variables would be a concern when turning a pin on or off (if the pin controls a solenoid that opens a valve) or when setting the position of a servo that manually operates a valve.
Local variables would be useful to save the values parsed from a command to set the time/date, but they are very small in comparison to the space used to hold the command.
PaulS:
Yes.
I can't imagine why local variables would be a concern when turning a pin on or off (if the pin controls a solenoid that opens a valve) or when setting the position of a servo that manually operates a valve.
I have, for example, a function which parses received wireless (currently bluetooth) messages. There is a switch which parses by the first character, leaving up to 15.
Some of these need processing. For example, 'r' takes two more ascii characters, the first to indicate which sprinkler, and the second for how long. so "r13" would result in turning on bank 1 for 2^3 seconds. (This isn't normal operation, it's there so I can be out there to work on them and tap my phone for a quick burst, instead of hollering to someone on the porch.). The global variables for currentSprinkler and sprinklerShutoffTime are then set, and the sprinkler turned on.
If I have a dozen different commands on the branches of the switch, each of which has one or two variable to calculate, allocating all of them every time the function is called.
[/quote]
Local variables would be useful to save the values parsed from a command to set the time/date, but they are very small in comparison to the space used to hold the command.
[/quote]
But those come out of different pools :). While I have comfortable RAM left, I have ROM to burn . . .