set varable as decimal and then wait from that decimal

motters

New Member
hi
i feel really bad as i have asked for help so much i am really sorry!!

but i have this problem probally my last as after this mini-project as i am going to start to learn to hand code :D

Problem
say the user click a button 20 time my code using count command, and counts that. and set it to A. A = 20

then i divide 1 by the variable A in this case 20 and set this to varable say B. 1 / 20 = 0.05
B = 0.05
but the varable that picaxe and logicator use round it up or down and does not keep the value 0.05.(value took from varable b)

so i now know that you can not set decimals to normal varables .
So i did some reasearch and found about word variables would they work?can i set a value of 0.05 to a word variable? if so how?

i then need that varable to feed the wait function. meaning that i need the wait function to wait 0.05 seconds

It sound simple but i can't get it to do it. i am using a 18m2 if that is any help.

thanks you very much for all your help :D
 
Last edited:

papaof2

Senior Member
PICAXE *only* supports integer math.
If you multiply your number by 100, then you can divide it - just remember where the decimal should be.
1 * 100 = 100 100/20 = 5
The ratios are the same (1:0.05 or 100:5).

Do whatever scaling is required to make the math integer math. Use all positive values.

Just remember that any value greater than 255 must be in a word variable:

b0 = 255 is OK
b0 = 256 is not

w1 = 255 is OK
w1 = 256 is OK
w1 = 65535 is OK
w1 = 65536 is not

John
 

motters

New Member
thanks

are ok thanks for that.
so what i want to do is pritty impossable then
as i want to wait for 0.05 second using a varable to set that time in the wait command.
ok then thanks ill have to think of another way lol :p
 

hippy

Ex-Staff (retired)
Not impossible, you just have approach it a different way. You want a delay of 0.05 seconds whan the input is 20, that is, 1 second / 20 = 0.05.

If you think in terms of milliseconds, that 0.05 seconds is 50 milliseconds, and 1000 / 20 = 50 milliseconds.

Luckily the PICAXE supports delays of milliseconds though not through the WAIT command with the value in a variable. You have to revert to using a Basic flowchart block and using PAUSE.

So you can Count A which will be 20,
Calculate B which will be 1000 / A,
and use a Basic flowchart block to activate "PAUSE varB"

As you seem to have realised yourself, you are programming at a level beyond that of most Logicator users and Basic language programming may be a better approach.
 

motters

New Member
thanks

are i see.
thanks for that i will be doing it that way then. i though there would be a way to do it :rolleyes: thanks

Though logicator will not be able to simulate the basic command though will it (this does not matter just like to know)?

and i can just program my chip as normal through logicator and picaxe program with the basic command?

thanks
p.s
is there any place where i can learn to code by hand a website or good documents

thanks everyone :D
 

hippy

Ex-Staff (retired)
I don't believe Logicator will simulate the Basic blocks. Easiest way is to try it and see !

But, yes, you can program your chip as normal. Logicator simply takes the Basic blocks and inserts them with the code it generates from the other flowchart blocks, this is then compiled and downloaded to the PICAXE.

The best way to learn coding by hand, Basic language programming, is by looking at the examples in the PICAXE manuals and data sheets, examples posted on the forum and elsewhere. Also there's the PIC -> Convert Flowsheet to BASIC (alt-F6) menu option which will let you see the code generated from a flowchart.

Pursue it as you probably did for flowcharting; start with simpler programs and commands, add more commands as you progress and it will soon fall into place.
 
Top