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
PICAXE CODE?
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
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
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
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
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
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
Who is online
Users browsing this forum: No registered users and 1 guest