Shop OBEX P1 Docs P2 Docs Learn Events
How to input binary numbers — Parallax Forums

How to input binary numbers

940775940775 Posts: 8
edited 2005-06-13 16:50 in BASIC Stamp
I have 2 switches A and B; when the A switch is pressed I want it to represent a 1, and a 0 for switch B. I want any combination of the two to total 5 bits to be stored for later use. How can I store the 5 bits in the order in which they were pressed?

I'm using the Basic Stack SX, and Pbasic.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-06-13 14:29
    Hello,

    ·· First you will have to focus on simply reading the switches.· Technically speaking they will both have to be active-high or active-low.· So they will both return either a 1 or a 0.· You will need a counter to count 5 inputs from these switches, and alter the BITs of a BYTE variable based on the current counter value and switch input.· On a given BIT, if switch A is pressed, make that BIT a 1, and if switch B is pressed, a 0, then move on to the next BIT (Update counter).· Perhaps a FOR...NEXT loop would be easiest.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • 940775940775 Posts: 8
    edited 2005-06-13 14:43
    Thanks Chris for responding so quickly.· Could you give me a sample code on how this is done.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-06-13 15:22
    Hello,

    ·· There are example codes for doing most of what I suggested in the BASIC Stamp Manual, as well as in various application codes within StampWorks and our Stamps In Class books.· I would suggest getting the "What's A Microcontroller?" text, a free download in PDF format from our website.

    http://www.parallax.com/detail.asp?product_id=28152

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • 940775940775 Posts: 8
    edited 2005-06-13 16:50
    Thanks, this is what I've been looking for.
Sign In or Register to comment.