PICAXE CODE?

Electronics Computer Programming Q&A
Post Reply
User avatar
Lenp
Posts: 1530
Joined: Thu Oct 26, 2006 8:11 pm
Location: Maryland
Contact:

PICAXE CODE?

Post by Lenp »

It appears that some commands in the PicAxe (and others) dialect will not accept variables, since they are 'reserved'

For Example

THIS WORKS
For b0=1 to 5
High b0
Next

THIS DOES NOT
For b0=1 to 5
IF PIN b0=1 THEN......
Next

The program needs to determine the status of 15 individual inputs, in 2 different ports and react accordingly.

I know that can be done with ''..if pin0=1 then... ''and on and on but that is inefficient

Am I missing something? Any suggestions to test a range of inputs in a loop would be appreciated!

Len
sghioto
Posts: 326
Joined: Wed Dec 26, 2007 5:16 pm
Location: Colorado
Contact:

Post by sghioto »

One possible way is to use the command "let pins = b0". This will make the variable b0 equal to the status of the input pins on the port in a binary notation. For instance if all the inputs are normally low then b0 will have a value of 00000000 or zero. Say inputs 1,2 and 4 are high then b0 will equal 00010110 or 22. Should be able to write the code using "gosub" routines for various combinations of inputs if that's what is required.
main:
let b0 = pins
if b0 = 0 then gosub routine1
if b0 = 22 then gosub routine2
if b0 = 5 then gosub routine3
etc
etc
goto main

Steve G
User avatar
Lenp
Posts: 1530
Joined: Thu Oct 26, 2006 8:11 pm
Location: Maryland
Contact:

Post by Lenp »

Steve,
I guess the real issue is that PicAxe appears not to support arrays, and some references to the I/O structure must be 'labels' and do not support variables. If pinX statement could be assigned to an array, or if it accepted a variable then it could be tested in a loop. Many commands will accept a variable. High,low,toggle,sound, are a few that do.

The ideal syntax might be...

For B0=0 to 7
High(low,toggle...)B0
Next
(This works)

For B0=0 to 7
iF pin B0=1 then .....
Next
(This does not)

Yes, 'pins' does return a value representative of the pins input but additional code, or masks, are required to extract each individual pin 's status.

So it appears that, for now, a line of code for each pin of interest is necessary.

Any other ides?

Len
sghioto
Posts: 326
Joined: Wed Dec 26, 2007 5:16 pm
Location: Colorado
Contact:

Post by sghioto »

Lenp,
Unfortunately not. I'm only a beginner at Picaxe myself. I did post a similiar question on the "Picaxe Forum" and most of the responses were over my head. I don't know exactly what you are trying to do with the circuit, but the code works and does save some memory space.
http://www.picaxeforum.co.uk/showthread.php?t=9590

Steve G
manie
Posts: 4
Joined: Thu Jan 01, 2009 9:42 am
Contact:

Post by manie »

What happens after the "then" statement in

For B0=0 to 7
iF pin B0=1 then .....
Next
(This does not)

You can only leave the For..Next loop with a Gosub before the "Next". If I'm off the mark, sorry.....
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests