Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Programming — Parallax Forums

BS2 Programming

Henry KuaHenry Kua Posts: 2
edited 2004-08-30 20:07 in BASIC Stamp
Hi there,
I am henry, i have a problem with my programming. I am now doing a project which interface to the NOKIA 30 Modem which can sent sms using switches.
Eg
Switch 1 is depressed message "Hazel how are u???" will be send out.
Switch 2 is depressed message "Programming is fun..." will be sent out.

but this will work when individual switches are drepressed and individual message will be sent out so when i press switch 1 it will·sent out message 1 only after message 1 sent out then i press switch 2 message 2 will sent out. but when i press switch 1 & 2 at the same time it cannot sent the two message so i wonder is it my programming problem or i need to put the message in que so that it will put the message in que and sent out individually if it sense which switch is depressed 1st. if both switch is depressed it must sent out 2 message so how to do it.

Thanks
Henry

Comments

  • BeanBean Posts: 8,129
    edited 2004-08-30 14:11
    Please post your program.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-30 17:06
    The problem probably has to do with the way you're scanning the switches -- if you're using BUTTON, this can lead to troubles (because BUTTON is usually used by itself in a loop). The key would be to read both buttons into a Nib variable so that you can hold onto the scan. Then check each bit and send the messages accordingly. This will give you the queing capability you're looking for.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • nick bernardnick bernard Posts: 329
    edited 2004-08-30 20:07
    Henry
    you can solve this with a priority encoder ic. althogh that would only be practicle if you have atleast 4 buttons.
    (a priority encoder works much like a multiplexer)

    however, if you're only reading 2 buttons you can easily handle any exceptions in software.
    if you go with jon's recommendation you'll read both buttons into a single nibble and have 4 different states or situations to handle, that is
    %0000
    %0001
    %0010
    %0011
    for robust code you should handle them in a single branch statement or other conditional. just make sure each input situation and exception is handled

    also you can read·the first button and if it is pressed,·ignore the other. thats how a priority encoder works.

    the latter method is simpler; yet, the first gives you more control of your inputs.

    just remember, when·you have x inputs, you have 2^x states to handle.

    i hope this helps

    rox on
    nick B
Sign In or Register to comment.