How to input binary numbers
940775
Posts: 8
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.
I'm using the Basic Stack SX, and Pbasic.
Comments
·· 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
·· 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