using #define constants in Decision and Calculation

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
kevgm
Posts: 1
Joined: Sat Apr 21, 2007 10:10 pm
Contact:

using #define constants in Decision and Calculation

Post by kevgm »

Hi

I've got "#define ALARM_DEBOUNCE 90" defined in the supplementary code Definitions and function declarations and I want to use ALARM_DEBOUNCE in a Calculation component as:

AlarmTimer = ALARM_DEBOUNCE

Similarly I want to use it in a Decision component:

if AlarmTimer = ALARM_TIMEOUT

This is so I don't have to enter "90" in multiple places which makes it easier to modify the alarm timout at a later date and less prone to error.

Flowcode doesn't seem to allow this, it says ALARM_TIMEOUT is an undeclared variable.

Is there any way to do this?

Thanks
Kevin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

Hello

An easier way to do this would be to declare a variable and then initialise it at the start of your program. I know that defines are different from variables but this should do the job. This way all of the calculation and decision icons will work correctly.

Mark
Posts: 209
Joined: Thu Oct 19, 2006 11:46 am
Location: Bakewell, UK
Has thanked: 20 times
Been thanked: 16 times
Contact:

Post by Mark »

Benj,

Whilst the solution works, the problem is that with large programs variable space quickly gets used up with what are effectively constant values, but which need a convenient way of being updated locally at compile time but not after.

Could I suggest you see how this could be achieved, preferably in flowcode itself. Some sort of pseudo variable in flowcode that is optimised out at compile time would be great (I expect there is a proper term for this). Program memory is rarely at a premium but data memory, especially when using integer math can be quickly used up.

Regards,

Mark
Go with the Flow.

Post Reply