Collect Input from a for loop
jasonpeinko
Posts: 20
Is there a way to create a FOR loop that will check inputs something like this:
for i=0 to 13
if INi=1 then pressed
next
for i=0 to 13
if INi=1 then pressed
next
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