Shop OBEX P1 Docs P2 Docs Learn Events
Problem coding Lookdown command with Variable (input switches) — Parallax Forums

Problem coding Lookdown command with Variable (input switches)

Jeff AltenJeff Alten Posts: 7
edited 2004-10-03 18:04 in BASIC Stamp
Hi,

I've been trying to write a code that checks a number of switches(right now two but in total there will be 6) and depending on their pattern will dish out different tasks for some motors and cams to pull things or push and lift etc.

· But the lookdown command isn't·listening to what I'm trying to do·and I can't figure out why.· I want it to compare the bits in a variable where the input states of the switches(2)·are stored(0,1,10,11) and give me back a decimal number I can work with for a branch or case command. As each·possible·combination·of the switches alters the action of the outputs.

· The problem is it will only take one reading as soon as the stamp is turned on or reset...after that the decimal number in Lookdown commands·result variable stays the same and even won't change·if the input switches are registering differently.

Help..........
Thanks,
Jeff




···············

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-03 18:04
    A couple things:

    Your aliases don't need to be a verbose as you're making them.· Instead of this:

    Switches.LOWBYTE.LOWNIB.BIT0

    ... you could simplify to this:

    Switches.BIT0

    Your LOOKDOWN table has decimal 10 instead of binary 2 (%10) -- this is proabaly causing your error.· Take a look a what I've attached -- it scans the switches and debounces them.·

    Finally, using LOOKDOWN the way you are is really a waste of code space.· You've only got two bits, and you want one of three values.· Using the subroutine in my program you could do this:

    Main:
    · DO
    ··· GOSUB Read_Switches:
    · LOOP UNTIL (switches <> 3)
    · ON switches GOSUB Sw_0, Sw_1, Sw_2
    · GOTO Main


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.