Four Switch Truth Table Have A Question about how to get it to work
sam_sam_sam
Posts: 2,286
What· I want to do is to have a way of LOCK- ing access to a· home made key board
I have try-ed a few ways of doing it but can not get it·to work like the Truth Table show below
Truth Table is as Follows
···············This is the right order························ ········ · These button are not·push in the right order
switch1 = 1··<....... 1····· ··^······switch1=·0···<.......4···^·· ···· =· 1··<.......·1····^·····=·1· <.......1··· ·^····=·1· <......3
switch2 = 1··<........2····· ··^······switch2=·1···<.......3···^······ ·=· 0··<.......·4····^··· ·=·1··<.......2·····^··· =·1· <......1···......> ·And so on
switch3 = 1··<........3······ ·^······switch3=·1···<.......2···^········=· 1··<.......·3····^·· · =·0··<.......4·····^··· = 1· <......2
switch4 = 1··<........4······ ·^······switch4=·1···<.......1···^········= ·1· <.......·2····^·· · =·1··<.......3·····^··· =·0· <......4
·I want to use this type of routine or something like it
Dose any one have any ·s on how to do this type of routine
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 11/3/2009 2:42:33 AM GMT
I have try-ed a few ways of doing it but can not get it·to work like the Truth Table show below
Truth Table is as Follows
···············This is the right order························ ········ · These button are not·push in the right order
switch1 = 1··<....... 1····· ··^······switch1=·0···<.......4···^·· ···· =· 1··<.......·1····^·····=·1· <.......1··· ·^····=·1· <......3
switch2 = 1··<........2····· ··^······switch2=·1···<.......3···^······ ·=· 0··<.......·4····^··· ·=·1··<.......2·····^··· =·1· <......1···......> ·And so on
switch3 = 1··<........3······ ·^······switch3=·1···<.......2···^········=· 1··<.......·3····^·· · =·0··<.......4·····^··· = 1· <......2
switch4 = 1··<........4······ ·^······switch4=·1···<.......1···^········= ·1· <.......·2····^·· · =·1··<.......3·····^··· =·0· <......4
·I want to use this type of routine or something like it
N=0 DO xbit = IN0 xx = xbit ^ x0 & x0 x0 = xbit N = N + xx DEBUG HOME, DEC ? xbit, DEC ? xx, DEC ? x0, DEC ? N PAUSE 100 LOOP UNTIL N = XX ' XX = Some Value
Dose any one have any ·s on how to do this type of routine
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 11/3/2009 2:42:33 AM GMT
Comments
But it looks like you have 4 pole switches so you have either combinations or permutations.
It depends if you can only switch one switch to one number or not, how to count.
If 1111 is the first combination then you just have to count in base 4 to get to 4444 (not using zero)
I think there are 256 combinations then.
If 1234 is the first combination (use each number only once) then 4321 will be the last and you'd count like
1243 1324 1342 1423 1432 4123 4132 4213 4231 4312 4321.
(There are a few ways to count that way, at least one should be easy to figure out.)
I think there are only 12 combinations then so the regular switches would be a little more secure
because there are 16 on-off combinations.
edit[noparse]:o[/noparse]ops I goofed, and didn't use 2 and 3 as the first number. There are 1x2x3x4=24 combinations.
Post Edited (VIRAND) : 11/3/2009 1:37:15 AM GMT
If there are 4 regular switches then it's too easy with S1 AND S2 AND S3 AND S4 = 1111
Thank You for your reply
They are 4 regular switches· but how I want to·do it not easy·
S1 AND S2 AND S3 AND S4 = 1111· This is true
·One· note .....>>>> I am ·Not Yelling......>>>>··This is what I do not want in this truth table that I am working on
This is NOT true in the type of Truth Table I want and·will NOT·WORK and all other combinations are NOT TRUE
S2·AND S1·AND S3 AND S4········ = 1111··Yes the switch Truth Table is true
S4 AND S3 AND S2 AND S1········ = 1111
·......>>>>>
........
.......
.......····· And· ALL other combinations are NOT true because the button's are not· PUSHed in the·right ORDER
.......
.......
.......······································ <<<<<<<·
·
_____________________________________________________________________________________________________________
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 11/3/2009 2:43:26 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
If these are 4 switches rather than push buttons then what you want to do is fairly difficult. The micro needs to know when you have finished setting up each combination so it can read it. The only way I can see of doing that is to:
- start with a fixed input (say 0000)
- read the setting after a fixed time passes (say 2 seconds)
- see if it matches the first combination
- repeat for as many combinations as you want
If you already have a keyboard connected why not use it to enter a sequence of key presses?
that use big letters for the logic function "&" as "AND".
I think if I got a clue from the other comments,
that you might want to consider using a gray code, or state machine,
(or maybe you would be as long as you switched only one at a time).
As long as one switch is switched at a time you can most easily
have a list of states in order, which maybe you called a truth table,
and if I'm wrong don't mind me.
I think the states would proceed like this then, with any mistake making a silent exit (start over)
from accepting the lock code.
Version 1:Turn on and off in order, like push buttons.
S1 S2 S3 S4
0000 (First expected switch state)
1000
0000
0100
0000
0010
0000
0001
0000 Lock/Unlock it (finished)
Version 2:Turn on in right order only then turn off switches,
0000
1000
1100
1110
1111 Lock/Unlock it (finished)
0000 ... This changes too many switches but the lock was done. It could mean reset the lock if you want.
I'm a little confused because you used the ^ symbol which means XOR, both in the code and in the
unwanted combinations. It's not clear to me why you are using it. I suppose it could encrypt the
switch order if that's what you intended and would make more sense about needing a truth table
but I don't know exactly what you are thinking.
However you program the lock, you could use at least one temporary LED to light up while you
are testing it to recognize the switch activity as correct, but as soon as it is working you should
remove it of course because it would make picking the lock very easy.
Remember to go back to the beginning of waiting for the first right switch if the wrong one is used.
My state numbers are the order of switches being switched that it waits for before going to wait for
the next one, and eventually the switching is done and the lock is controlled. If you do it this way
then be sure to debounce switches (Repeat 100000 for a delay) so the same switch doesn't look like
the wrong one while it is still being used.
Gray code just means a sequence where only one bit (or switch) changes at a time to get to the next step.
State machine means a sequence of events is followed in an order and may determine what action is
taken. The switch lists are a sequence of events which activate lock only on the last one, and
if a wrong event (switch) happens then it should restart waiting for the first event instead of stay waiting
for the correct one, or else even a baby will quickly pass all the correct and wrong ones.
Interesting conversation.
Suppose you had a 4-postion switch. Each position would be connected to an input.
Also have a single push-button switch connected to an input.
The procedure would be to turn the selector switch to a position then push and release the button to tell the micro to read which input was on.
The micro stores the number and the operator moves the switch to another postion and hits the push button again. The micro stores the second input.
This would continue until either the right combination is entered or a wrong digit is entered and the micro resets the numbers. Quite flexible in that the code can be of any length.
A simple If statement would complete when the right sequence of inputs is seen.
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
Tom Sisk
Interesting conversation.
Suppose you had a 4-position switch. Each position would be connected to an input.
Also have a single push-button switch connected to an input.
The procedure would be to turn the selector switch to a position then push and release the button to tell the micro to read which input was on.
The micro stores the number and the operator moves the switch to another position and hits the push button again. The micro stores the second input.
This would continue until either the right combination is entered or a wrong digit is entered and the micro resets the numbers. Quite flexible in that the code can be of any length.
A simple If statement would complete when the right sequence of inputs is seen.
This is an Interesting· ·Could you give me an example of how you would do this·in a·code routine
___________________________________________________________________________________________________________________________
VIRAND
This is what I was looking for.....>>>>
I think the states would proceed like this then, .......>>>>>with any mistake making a silent exit (start over)
·from accepting the lock code.
Version 1:Turn on and off in order, like push buttons.
S1 S2 S3 S4
0000 (First expected switch state)
1000
0000
0100
0000
0010
0000
0001
0000 Lock/Unlock it (finished)
How would I write a routine to do this
I'm a little confused because you used the ^ symbol which means XOR, both in the code and in the
unwanted combinations. It's not clear to me why you are using it.
I· was using this to mean ^ UP I am sorry if I made it·a little confusing for you or any one else
to show the truth table I want to use
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 11/5/2009 12:32:33 AM GMT
·· Tied up finishing off another project at the moment.
·I'll see if I can put something together·over the next couple of days.
·But, its not too complicated:
·· Set up an array to hold the attempts.
··Set up a loop which will go through as many times as you want the code to have digits.
·· Perhaps have an LED to blink to show that its waiting for the first attempt.
··· Set the selector switch. Push the button. Compare the value to the first digit of the real code. Use the INA, INB, etc to read selctor sw.If good, loop and wait for next attempt. If bad, erase all attempts and go back to beginning.
··· Use the BUTTON command to debounce the push button input. Selector switch inputs don't need debounce.
··· Use IF try(0) and try(1) and try(2) and try(3) to confirm the right code.
·Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
Post Edited (stamptrol) : 11/5/2009 1:01:36 PM GMT
·Maybe assign a value to the 4 keys 0,1,2,3·· binary 00,01,10,11.
Then assign a place(shifting and adding)·for each press in a byte xx_xx_xx_xx (or word for multiple presses of the keys)
Then test the byte. 11_01_00_10 (or word )
One key may get pressed more than once and one key may not get pressed at all if you desire.
Post Edited (Propability) : 11/5/2009 8:17:15 PM GMT