Shop OBEX P1 Docs P2 Docs Learn Events
Collect Input from a for loop — Parallax Forums

Collect Input from a for loop

jasonpeinkojasonpeinko Posts: 20
edited 2007-05-02 21:31 in BASIC Stamp
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

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-02 19:26
    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
  • jasonpeinkojasonpeinko Posts: 20
    edited 2007-05-02 19:44
    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-02 20:19
    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
  • DrunlarDrunlar Posts: 1
    edited 2007-05-02 20:19
    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.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-05-02 20:36
    Drunlar -

    PBASIC is an interpreted language, not a compiled language. Thus, there is no assembly code generated.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • hitswarehitsware Posts: 156
    edited 2007-05-02 21:16
    Bruce Bates said...
    Drunlar -

    PBASIC is an interpreted language, not a compiled language. Thus, there is no assembly code generated.

    Regards,

    Bruce Bates

    Even if 'interpreted' isn't assembly code still generated?
    Just that a interpreted file (executable) is not created?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-02 21:31
    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
Sign In or Register to comment.