Problems with WAIT commands

Tricky Dicky

Senior Member
I have been trying to produce a program that switches on a series of LEDs in sequence. The speed of the sequence is determined by Wait commands keeping each LED on for a set period. To vary the speed of the sequence I have used a potentiometer and Readadc the value thus obtained is used in a variable in the Wait command to produce varying delays for the LED ONs. Written in Basic in Programme Editor this produces the desired effect, but with Logicator I am getting either frenetic flashing or deadly slow and the simple maths seems completely baffling.

It seems Logicator treats standard numerical delays and variables differently. As an example, Entering 0.5 in the Wait cell produces the following line of Basic;

pause 500 'Wait command

However, when using a variable the following two lines of Basic are produced;

let w6 = varB * 1000 'convert from s to ms
pause w6 'Wait command

If an Expression cell is used to assign Variable B = 1 / 2, which would make Variable B = 0.5
the first of the above lines should produce w6 = 500 and the second line should then be the equivalent of the pause 500. When downloaded this produces a very brief flash through all the LEDs as if the conversion to ms had not occurred. Conversley if Var B is given the value 250*2 in the expression and Variable B = 500 the s to ms conversion applies and the delays are equivalent to 1 min. presumably because B = 500,000ms well in excess of the 65,000 max. Can you explain what is going on or is this a fault in Logicator.

Richard
 

Technical

Technical Support
Staff member
If an Expression cell is used to assign Variable B = 1 / 2, which would make Variable B = 0.5
...
Conversley if Var B is given the value 250*2
It's not a fault, just a misunderstanding of byte variables. Neither of these assumptions work, because variables A-H are byte 'containors', and can therefore only contain whole numbers between 0-255.

So 1/2 is not 0.5, it is rounded down to 0, as fractions are not allowed in variables.
And 250*2 is not 500, it is 244 after the overflow (500-256).

The 'wait 0.5' on screen is purely cosmetic, internally the PICAXE uses 'pause 500' as wait with a fractional number is not acceptable in PICAXE BASIC. However as Logicator has traditionally always used 'seconds' not 'milliseconds' on screen (as this is easier for younger students), when a number is in a variable it is also assumed to be a seconds value (hence the * 1000 when converted to PICAXE pause milliseconds).

In this scenario (readadc value becoming the exact delay in ms) the best option is to not use a wait cell but use a BASIC cell containing the text 'pause varB'. Then the raw adcvalue will be output in milliseconds.
 

Tricky Dicky

Senior Member
Thanks Technical will do that. Incidently the project is a metronome hence the need to vary the waits in ms rather than secs. for how long each LED is on.

Ta!

Richard
 
Top