Page 1 of 1

using #define constants in Decision and Calculation

Posted: Sat Apr 21, 2007 10:18 pm
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

Posted: Mon Apr 23, 2007 9:45 am
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.

Posted: Mon Apr 23, 2007 3:53 pm
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