View Full Version : Using Variables
jonny foster
01-07-2009, 16:28
Hiya, I'm writing a program on logicator for a metronome and for the sake of simplifying the program I want to use variables to control the wait time (which would control the tempo of the metronome). The problem is that it appears to be impossible to assign non-integer values to a variable. do the variables have to be integers? and also say the basic code is let VarA = 5
pause VarA will it pause 5 seconds or 0.005 seconds? any advice even if what I'm asking is impossible is much appreciated, thanks.
Technical
01-07-2009, 16:49
You can do both, you have two options:
Use an expression cell to say
A=5
then a normal wait cell to say
wait A
As wait is in seconds this will give you a 5 second delay.
or
Use an expression cell to say
A=5
then a 'BASIC' cell to say
pause varA
This will pause 5ms (0.005s)
PICAXE (and almost all microcontrollers) don't understand fractions - you have to use whole numbers.
jonny foster
01-07-2009, 18:47
Thank you, so if i'm after a wait for 0.8 seconds I would need to give a variable the value 800 but that's not going to work is it because it's larger than 255. Is there somewhere that can store larger numbers or would let VarA = 200 pause 4*VarA be a valid piece of code? thanks
jonny foster
01-07-2009, 19:06
I've seen code with let w1 = whatever, can they store higher numbers?
Check Manual 2, especially page 10 and following. In brief, the "w" variables (word variables as opposed to byte variables) can hold numbers between 0 and 65535. Note the a "w" variable is composed of 2 "b" variables, that is, w0 is made up of b0 and b1--so when using word and byte variables you have to be careful not to change a byte variable which is part of a word which you are otherwise using.
Technical
01-07-2009, 21:14
Logicator only uses byte variables (0-255).
But you can use word variables if you use BASIC cells e.g.
let w6 = 800
then
pause w6
Powered by vBulletin® Version 4.1.11 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.