Shop OBEX P1 Docs P2 Docs Learn Events
More buttons and LED's — Parallax Forums

More buttons and LED's

K. ReichmanK. Reichman Posts: 9
edited 2005-11-15 15:22 in BASIC Stamp
Hi,
Please help me. I must have seven buttons on BS2. When I touch one button, BS2 must sent on serial character "1", and so on until character "7". There is 2 problems: 1. When I release one button, I want BS2 to continue to send the character, until I press the other button, .... 2. On each buttons is atached one LED. I want LED remain on after button is released.

PLEASE HELP ME !!!


Thanks


Valentin

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-14 20:13
    Here's·how I would do it:

    Main:
    · select =·NCD (INL & %01111111)
    · IF·select = 0 THEN Main············ ' try again if none pressed

    · OUTH = %00000000··················· ' clear old LED
    · select = select - 1················ ' z-align
    · HIGH select + 8···················· ' light new LED
    · SEROUT Sio, Baud, [noparse][[/noparse]"0" + select]··· ' transmit character
    · GOTO Main

    P0 - P7 are the button inputs (active high), P8 - P14 are the LED outputs

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 11/15/2005 1:15:26 PM GMT
  • metron9metron9 Posts: 1,100
    edited 2005-11-15 06:29
    Not sure how that works,

    I read DCD sets a bit of a Word using a 4 bit value, that is it sets any bit 0 through 15 for the integer value 0 through 15 given as its input.

    INL is an 8 bit value so bits 4 thru 7 are not looked at by the command.

    results would be 2,4 16 and 256 for bit 0,1,2,3

    Select is also a keyword so you cant use it as a variable

    Could you just use

    main:
    ledvar=INL & %01111111 'Get the input bit that is set mask to 7 switches
    outH=ledvar 'Set the bit to light the led (shift to position first depending on pins used)
    output serial character
    probbly pause for some delay
    goto main


    If that's wrong I must be in need of a vacation cause I just cant see how it works.
  • K. ReichmanK. Reichman Posts: 9
    edited 2005-11-15 08:13
    Thanks for your answer...

    For the moment, didn't work. Can you send me please a diagram with connection of one button and one LED please?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-15 13:16
    Whoops, sorry, I should have used NCD instead of DCD -- that was written off the top of my head as an idea to give you guidance, and not intended to be a full working program.

    NCD will return the input that is pressed (+1) -- that way you get one value, even if you accidentally press two buttons.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • metron9metron9 Posts: 1,100
    edited 2005-11-15 15:00
    There are so many things i don't know about Pbasic. I knew I could learn something new again, thank's for clearing that up Jon.
  • K. ReichmanK. Reichman Posts: 9
    edited 2005-11-15 15:09
    On Parallax experiment #15 "Deboucing Multiple Inputs" it's an example about four inputs. How can extend for eight inputs?

    Tx
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-15 15:22
    It's easy: use a byte variable instead of a nibble, and read a byte-wide port (i.e., INL or INH) instead of a nibble-wide port.

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