Values for delay timer

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

Moderators: Benj, Mods

Post Reply
woodp1
Posts: 2
Joined: Wed Oct 04, 2006 11:14 am
Location: Dunboyne Co. Meath
Contact:

Values for delay timer

Post by woodp1 »

Hello
I am trying to use delay values in seconds and part second values to 2 decimal places for example 2.15 . How can i enter this value for a delay.

Thank you
Paddy

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

If you have a constant delay time, you can simply use a 2s delay followed by a 150ms delay.

If you have this delay time as a variable, you need to be a little clever. The value of a variable passed to the delay icon must be between 0 and 255, so you will need to do a little bit of work...

I will assume you have 2 variables, SEC for the second part of the delay and FSEC for the fractional part of the delay (a value between 0 and 99, meaning 0 to 990 ms). You could create a new macro which contains the following in a 'C' code icon:

Code: Select all

//delay the whole number of seconds
delay_s(FCV_SEC);

//delay the fractional part
if (FCV_FSEC >= 80)
{
	delay_ms((FCV_FSEC - 80) * 10);
	delay_ms(200);
	delay_ms(200);
	delay_ms(200);
	delay_ms(200);
} else if (FCV_FSEC >= 60) {
	delay_ms((FCV_FSEC - 60) * 10);
	delay_ms(200);
	delay_ms(200);
	delay_ms(200);
} else if (FCV_FSEC >= 40) {
	delay_ms((FCV_FSEC - 40) * 10);
	delay_ms(200);
	delay_ms(200);
} else if (FCV_FSEC >= 20) {
	delay_ms((FCV_FSEC - 20) * 10);
	delay_ms(200);
} else {
	delay_ms(FCV_FSEC * 10);
}
There will be other methods, but this should work (although I haven't tried it).

An alternative approach would be to have your delay variable contain a number between 0 and 255, where each increment of this variable represents a whole number of milliseconds. This approach depends on your required maximum value for the delay. Here's an example which will hopefully explain what I mean:

A "DELAY" value of 1 could represent 8ms. In which case, your maximum delay available would be 8*255 = 2.04 seconds. Your code for the delay would then be 8 consecutive delay (ms) icons, each with the "DELAY" variable as a parameter.

This second appropach has the advantage of being simpler to code (it avoids 'C'), but it does mean that the variable does not equate to a convenient delay time (for example, if DELAY=100, the actual delay would be 0.8 seconds).

I hope this helps.

woodp1
Posts: 2
Joined: Wed Oct 04, 2006 11:14 am
Location: Dunboyne Co. Meath
Contact:

Post by woodp1 »

Thanks Steve for the information
Paddy

Post Reply