Picaxe 40M2 and variables using Blockly

Garahbara

New Member
Hi all,

Yes it's me of the model railway level crossing again. All is going well, and the boom gates go up and down using servo motors and lights flash and bell rings etc, all coded and working with a switch.

However, I now need to detect the trains. Using LDRs. 13 of them. And I need associated variables for each to trigger/comparison values etc.

The 40M2 seems to allow only 28 full word variables.

Blocky's "set variable" for the 40M2, generates symbol commands "symbol var_Detect_Train = w27 " using a full-word variable. I do not need that resolution for LDR sampling, plus I do need a lot more variables than the 28 allowed for the 40M2. Can I get Blockly to generate a "byte" variable. ie. "symbol var_Detect_Train = b27". Of which I can have more than 28, but how many "byte" variables can I have on a 40M2?

I want to use Blocky, as it will do all I need, plus it lets you select variable names from a drop-down box, avoiding retyping numerous variable names and making typos. A lot of the logic will be "cloned", just using different variable names in each iteration.

Taa muchly in advance for any advice here.

Alan.

TOOT!
 

lbenson

Senior Member
Of course, there is no 40M2--just the 40X2, which has 28 word variables, or 56 byte variables occupying the same space.

I know nothing about Blocky, so can't help there, but would suggest that with something as complex as you are attempting, you would do well to switch to real PICAXE basic. With that, you would also be more assured of getting help. It's possible that no one has ever attempted something as complex as you propose using Blocky.
 

Technical

Technical Support
Staff member
Blockly variables are predefined, but you can convert the blockly design to basic and then edit the basic as required.
 

Volhout

New Member
If you convert to PICAXE basic, you have a max of:
32 bit variables (1 or 0) eating up words w0 and w1
+
52 byte variables (0-255) eating up the rest of the words (W2-27)
So the absolute maximum is 84 variables.

Then thee is 1024 bytes scratchpad memory. That memory can not be used for variables, but you can use a variable to point to a certain memory location in that memory block, and store data/retrieve data from it. Since it is 1024 bytes in size you need a word variable to point to a memory location.
 

Aries

New Member
Then thee is 1024 bytes scratchpad memory. That memory can not be used for variables, but you can use a variable to point to a certain memory location in that memory block, and store data/retrieve data from it. Since it is 1024 bytes in size you need a word variable to point to a memory location.
You can use the ptr variable to point to scratchpad locations and to some extent use @ptr (@ptrinc, @ptrdec) as a variable. There is also the rest of RAM above the 56 byte variables (i.e. 200 in total) which can similarly be referenced with @bptr etc. As has been said in other threads, you do not have to use a byte or word variable for each individual item - the "trick" is to store them in RAM or scratchpad, and then load them into temporarily-used byte or word variables when you need to use them, storing them back if they have been changed.
 

AllyCat

Senior Member
Hi,
I want to use Blocky, as it will do all I need, ........, avoiding retyping numerous variable names and making typos. A lot of the logic will be "cloned" ....
It rather seems that it won't. ;)

But as mentioned above, by using @bptr and maybe @ptr, you can have access to literally hundreds of variables. Also, by using Cut-and-Paste, perhaps associated with Search/Find-and-Replace, you should be able to "clone" PICaxe Basic routines much more accurately and conveniently than with Blockly. Maybe it's better than the (IMHO horrible) "flowchart" software, but I still find the machine-generated "generic" labels, variable names and overall structure, appalling compared with well-constructed "human" code.

However, you shouldn't need to "clone" subroutines numerous times anyway. With the "indirection" possible with @bptr and just peek/poke with a variable "pointer" byte, a single routine should be able to service many sensors. Alternatively, the PE6 "Macro" facility allows you to write just one routine and "pass" variables with different names into it. There are probably (far) better tutorials, but take a look at the "Macros:" subheading in Post #12 of a (current) thread that I have been working on for some time. :)

Cheers, Alan.
 
Top