The loop you have will check the input each pass through the loop. As written this will happen very quickly and the program will most likely end before there is activity on the line. Could you elaborate more on what you’re trying to do?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Chris Savage Parallax Tech Support
Basically i have a row of buttons that i want to check with a for loop to cut down on the length of code, the above code returns an error so it wont work.
You can look at the entire range of buttons with:
btn = INS & $3FFF
if btn <> 0 then pressed
' continue here if none pressed
pressed:
for i = 0 to 13
if i & 1 = 1 then pressedi
i = i / 2
next i
' should not fall through here
pressedi:
' i is number of first bit set to 1
I understand your objective and I am not sure on the answer.
I purpose another question. Are you trying to cut back on the code with a loop in order to make your code look cleaner or are you attempting to take up less memory space on the chip?
If you goal is less memory space on the chip unless I am mistaken this change will not do you any good. When the code is compiled to assembly it should take up approximately the same amount of room either way.
The code is tokenized during compilation. This doesn’t generate assembly code, or more appropriately object code but rather specialized codes (tokens) that the interpreter reads to know what assembly code within itself to execute to produce the equivalent result.
Back on subject…I now see the little ‘i’ you had next to your IN statement. I hadn’t seen that before and thought you were checking P1 14 times. Now that I see you wanted an index you would actually use IN0(i) but I would suggest Mike’s approach since it will read the pins all at the same time. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Chris Savage Parallax Tech Support
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
btn = INS & $3FFF
if btn <> 0 then pressed
' continue here if none pressed
pressed:
for i = 0 to 13
if i & 1 = 1 then pressedi
i = i / 2
next i
' should not fall through here
pressedi:
' i is number of first bit set to 1
I purpose another question. Are you trying to cut back on the code with a loop in order to make your code look cleaner or are you attempting to take up less memory space on the chip?
If you goal is less memory space on the chip unless I am mistaken this change will not do you any good. When the code is compiled to assembly it should take up approximately the same amount of room either way.
PBASIC is an interpreted language, not a compiled language. Thus, there is no assembly code generated.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just that a interpreted file (executable) is not created?
Back on subject…I now see the little ‘i’ you had next to your IN statement. I hadn’t seen that before and thought you were checking P1 14 times. Now that I see you wanted an index you would actually use IN0(i) but I would suggest Mike’s approach since it will read the pins all at the same time. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support