Entering a number using 4 switches. There must be abetter way

I want to enter a number between 0 and 15 using 4 dip switches. I attached the schematic and the code which, I think, should work. But there must be a better way. Any sugestions?
Code:
Symbol Zero = b0
Symbol One = b1
Symbol Two = b2
Symbol Three = b3
Symbol Total = b4

	Main:
If Pin5 =0 then let Zero=0 else let Zero=1
Endif
If Pin2 =0 then let One=0 else let One=2
Endif
If Pin1 =0 then let Two=0 else let Two=4
Endif
If Pin0 =0 then let Three=0 else let Three=8
Endif
Total= b0+b1+b2+b3
Pause 5000
Goto Main
 

Attachments

Last edited:

moxhamj

New Member
You could use something like this: http://www.jaycar.com.au/ and search for product SR1222

It is a binary coded rotary switch. If you want something bigger, you could use a keypad but it ties up different wires and needs a bit more code.

There are also optimisations to the code eg

b0=pins ' will read in the status of the pins
b0=b0 and %00001111 ' select only the lower 4 input pins

and then the number is in b0.
 
Last edited:

moxhamj

New Member
There you go. Within two posts the program is down to one line. Where can I get some of that krypton?!

Just out of interest how many times do you need to enter this number. Once when you build the board? Many times an hour? Is the user proficient in binary? Is it ok to have 4 toggle switches and a piece of paper with the decimal numbers and their binary equivalent?
 
Last edited:
Sorry guys, if you look at the schematic you will see that I can't use pins 3 and 4. The circuit includes 2 I2C devices (not shown)
The number will be entered once a year. I will tape a paper to the back of the PCB with the switch setings for numbers from 0 to 15
 
Last edited:

moxhamj

New Member
Ok. I'm sure this can be improved but how about
let b0=pins and %00100111' mask
b1=b0 and %00000111' get lower 3 bits
if bit5=1 then
b1=b1+8
endif
 

hippy

Ex-Staff (retired)
b0 = pins
bit3 = bit5
b0 = b0 & $0F

Alternatively you could build a ladder circuit on the ADC and just use one line but the design will be slightly more complicated.
 

westaust55

Moderator
You indicated that you were trying to enter the values 0 to 15

Jaycar rotary switch SR1222 which is Decimal to BCD and only does the values 0 to 9

But right next to it is in the catalogue is SR1220 which is HEX to BCD and does the range 0 to 15 (F) for the same $5-95.
 
You indicated that you were trying to enter the values 0 to 15

Jaycar rotary switch SR1222 which is Decimal to BCD and only does the values 0 to 9

But right next to it is in the catalogue is SR1220 which is HEX to BCD and does the range 0 to 15 (F) for the same $5-95.
I saw that when Dr. Acula posted the link to Jaycar. I intend to use the hex switch. But even if I don't use the dip switches, I learned a couple of programing techniques from you guys.
 

krypton_john

Senior Member
For some reason I have always found the manuals hard to read in some ways and have learnt a lot from this forum. I think it's just me - the manuals are generally well written.
 
Top