View Full Version : How to input binary numbers
940775
06-13-2005, 08:25 PM
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.
Chris Savage
06-13-2005, 09:29 PM
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 (mailto:csavage@parallax.com)
940775
06-13-2005, 09:43 PM
Thanks Chris for responding so quickly.· Could you give me a sample code on how this is done.
Chris Savage
06-13-2005, 10:22 PM
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 (mailto:csavage@parallax.com)
940775
06-13-2005, 11:50 PM
Thanks, this is what I've been looking for.