binary password lock.
' {$STAMP BS2}
' {$PBASIC 2.5}
INPUT 0
INPUT 1
INPUT 2
INPUT 3
'HIGH 15
'PAUSE 2000
'LOW 15
no1 VAR Byte
no2 VAR Byte
no3 VAR Byte
no4 VAR Byte
pw1 VAR Bit
pw2 VAR Bit
pw3 VAR Bit
pw4 VAR Bit
digit VAR Nib
DO
IF (IN0 = 1) THEN
no1 = 1
ELSE
no1 = 0
ENDIF
IF (IN1 = 1) THEN
no2 = 2
ELSE
no2 = 0
ENDIF
IF (IN2 = 1) THEN
no3 = 4
ELSE
no3 = 0
ENDIF
IF (IN3 = 1) THEN
no4 = 8
ELSE
no4 = 0
ENDIF
digit = no1 + no2 + no3 + no4
IF (digit > 0) THEN
DEBUG DEC digit, CR
ENDIF
IF (digit = 1) THEN
pw1 = 1
ELSE
pw1 = 0
pw2 = 0
pw3 = 0
pw4 = 0
ENDIF
IF (digit = 2 AND pw1 = 1) THEN
pw2 = 1
ELSE
pw1 = 0
pw2 = 0
pw3 = 0
pw4 = 0
ENDIF
IF (digit = 3 AND pw2 = 1) THEN
pw3 = 1
ELSE
pw1 = 0
pw2 = 0
pw3 = 0
pw4 = 0
ENDIF
IF (digit = 4 AND pw3 = 1) THEN
pw4 = 1
ELSE
pw1 = 0
pw2 = 0
pw3 = 0
pw4 = 0
ENDIF
IF (pw4 = 1 AND digit = 12) THEN
HIGH 15
PAUSE 1000
LOW 15
pw1 = 0
pw2 = 0
pw3 = 0
pw4 = 0
ENDIF
LOOP
I really need to tidy up this code. I have a really noobish way of the password lock. This is wired to a DTMF decoder outputting in binary. I need help making the DATA and READ commands to make a password lock. I have seen examples but I cant put them to my use. Brain overload. Somebody please help me to make this code more simple with a
password DATA "1, 2, 3, 4
at the start.
If anyone knows what I am talking about and can help please do

Thanks heaps
Microman171
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 + 1 = 10 Base 2
2 + 2 = 10 Base 4
3 + 3 = 10 Base 6
4 + 4 = 10 Base 8
5 + 5 = 10 Base 10

Comments
' {$STAMP BS2} ' {$PBASIC 2.5} GH 15 'PAUSE 2000 'LOW 15 inPw VAR NIB pw VAR NIB eeAddr VAR WORD ' I'm presuming 4 bit passwords here, so you can use decimal 0-15 or binary 0-1111 Passwords DATA %1111, 14, %1011, 9, $FF ' $FF terminates pw list Main: inPw = INA ' set pw = pins 0...3 eeAddr = Passwords DO READ eeAddr, pw IF pw = $FF THEN EXIT IF pw = inPw THEN DEBUG "Yes, that is a correct password", CR HIGH 15 PAUSE 1000 LOW 15 EXIT ELSE eeAddr = eeAddr + 1 ENDIF LOOP GOTO Main▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 + 1 = 10 Base 2
2 + 2 = 10 Base 4
3 + 3 = 10 Base 6
4 + 4 = 10 Base 8
5 + 5 = 10 Base 10
- pins 0-3 are inputs where a binary password is "entered"
- input password is compared with password(s) in list
- if there is match, make pin 15 high for 1 second
- otherwise try again with input password
The only thing I wasn't sure of is that I *think* you are not allowing %0000 to be a password, so you could check for that before entering the do loop. Up to you.
' {$STAMP BS2} ' {$PBASIC 2.5} inPw VAR NIB ' password taken from input pw VAR NIB ' password read from data eeAddr VAR WORD ' pointer to address in bytes of data ' I'm presuming 4 bit passwords here, so you can use decimal 0-15 or binary 0-1111 ' below is a list of passwords that will "work". The list can be any length, the list ends ' with $FF -- i.e., $FF can't be a good password Passwords DATA %1111, %1110, %1011, %1001, $FF Main: inPw = INA ' copy the state of pins 0..3 to inPw IF inPw = 0 THEN Main ' no pw entered, try again eeAddr = Passwords ' otherwise point eeaddr to start of data list DO READ eeAddr, pw ' read the byte at eeaddr into pw IF pw = $FF THEN EXIT ' is the byte $FF? if so, then list is over, you are done, exit the loop IF pw = inPw THEN ' does password from list match what was input? DEBUG "Yes, that is a correct password", CR ' yes, debug that it's good HIGH 15 ' set pin high PAUSE 1000 ' wait 1 second LOW 15 ' set pin low EXIT ' exit the loop ELSE ' password did not match, so... eeAddr = eeAddr + 1 ' point to next byte in the data list ENDIF LOOP ' and check the next byte GOTO Main ' list ended or password match was found, so loop is over, start again▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 1/24/2008 12:39:08 AM GMT
Thanks again
Dan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 + 1 = 10 Base 2
2 + 2 = 10 Base 4
3 + 3 = 10 Base 6
4 + 4 = 10 Base 8
5 + 5 = 10 Base 10
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Thanks for the help!!
Dan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 + 1 = 10 Base 2
2 + 2 = 10 Base 4
3 + 3 = 10 Base 6
4 + 4 = 10 Base 8
5 + 5 = 10 Base 10
' {$STAMP BS2} ' {$PBASIC 2.5} inPw VAR Word ' password built up from digits of input pw VAR Word ' password read from data eeAddr VAR WORD ' pointer to address in bytes of data i VAR Nib ' index counter ' below is a list of passwords that will "work". The list can be any length, the list ends ' with $FFFF -- i.e., $FFFF can't be a good password - that would be 16-16-16-16 anyway ' note that the digits are in hex -- i.e., these are BCD numbers where each nib is a digit Passwords DATA Word $1234, Word $9999, Word $3456, $FFFF Main: ' here you will need to do some work because I don't quite get how are you are readiing each ' digit, i.e., each set of 4 bits in to a digit in the PW FOR i = 3 TO 0 ' get 4 digits, this is backwards because if you were entered "7821" you'd want 7 in nib3, 8 in nib2, etc inPw.NIB0(i) = INA ' copy the state of pins 0..3 to inPw NIB i (each digit) PAUSE 300 ' or whatever you do between enters of each digit NEXT ' now you've got BCD numbers as "digits" in each nib position of the Word inPw IF inPw = 0 THEN Main ' no pw entered, try again eeAddr = Passwords ' otherwise point eeaddr to start of data list DO READ eeAddr, Word pw ' read the Word at eeaddr into pw IF pw = $FFFF THEN EXIT ' is the Word $FFFF? if so, then list is over, you are done, exit the loop IF pw = inPw THEN ' does password from list match what was input? DEBUG "Yes, that is a correct password", CR ' yes, debug that it's good HIGH 15 ' set pin high PAUSE 1000 ' wait 1 second LOW 15 ' set pin low EXIT ' exit the loop ELSE ' password did not match, so... eeAddr = eeAddr + 1 ' point to next byte in the data list ENDIF LOOP ' and check the next byte GOTO Main ' list ended or password match was found, so loop is over, start again▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 + 1 = 10 Base 2
2 + 2 = 10 Base 4
3 + 3 = 10 Base 6
4 + 4 = 10 Base 8
5 + 5 = 10 Base 10
the password would be 4 sets of 4-bit binary outputted onto 0 - 3. This is actually going to be my science fair project. A cell phone controlled door latch. You ring up the phone connected to the BS2 and dial the code over the line. Each tone is converted to 4-bit binary. The BS2 need to be able to read each digit and check if they match the password/s stored in the BS2.
You help is greatly appreciated
Dan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 + 1 = 10 Base 2
2 + 2 = 10 Base 4
3 + 3 = 10 Base 6
4 + 4 = 10 Base 8
5 + 5 = 10 Base 10
INA 1st time - bits 12..15 (digit 4)
INA 2nd time - bits 8..11 (digit 3)
INA 3rd time - bits 4..7 (digit 2)
INA 4th time - bits 0..3 (digit 1)
Since the "good" passwords are also stored as BCD, e.g., $4321, then you can just match pw to inPw as above.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Greatly appreciated
Dan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 + 1 = 10 Base 2
2 + 2 = 10 Base 4
3 + 3 = 10 Base 6
4 + 4 = 10 Base 8
5 + 5 = 10 Base 10
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
0
0
0
0
0
0
2
2
2
2
2
2
2
0
0
0
0
0
3
3
3
3
3
3
0
0
0
0
0
0
0
0
0
4
4
4
4
4
4
4
light
0
0
0
0
0
0
0
0
0
0
0
0
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 + 1 = 10 Base 2
2 + 2 = 10 Base 4
3 + 3 = 10 Base 6
4 + 4 = 10 Base 8
5 + 5 = 10 Base 10
This takes care of infinite 0's. But what you would need to is add a counter in -- if 4 digits are received, then check.
No, if you counted 0 through 3 then it *would* be backward.... it's like this:
If I type $4 first, really that's the MOST SIGNIFICANT digit -- which would be NIB3 (the highest four bits of the pw). Humans *read* digits most-significant to least-significant; but if you are INDEXING digits, 0 is the LEAST significant. Try it with a debug and see:
Here's my earlier code with a digit counter. If it were me, I would put in another counter to *roughly* time things. If you don't get 4 digits in 30000 ticks or some such number, reset the digit counter (otherwise the Stamp could wait years for the 4 digit).
' {$STAMP BS2} ' {$PBASIC 2.5} inPw VAR WORD ' password built up from digits of input pw VAR WORD ' password read from data eeAddr VAR WORD ' pointer to address in bytes of data digCntr VAR NIB ' below is a list of passwords that will "work". The list can be any length, the list ends ' with $FFFF -- i.e., $FFFF can't be a good password - that would be 16-16-16-16 anyway ' note that the digits are in hex -- i.e., these are BCD numbers where each nib is a digit Passwords DATA WORD $1234, WORD $9999, WORD $3456, $FFFF Main: ' here you will need to do some work because I don't quite get how are you are readiing each ' digit, i.e., each set of 4 bits in to a digit in the PW FOR digCntr = 3 TO 0 ' get 4 digits, this is backwards because if you were entered "7821" you'd want 7 in nib3, 8 in nib2, etc DO ' you could put a word sized counter here; if the counter exceeds some number before you get all 4 digits ' then back to main and start all over LOOP WHILE INA = 0 ' keep looping until you get non-zero input inPw.NIB0(digCntr) = INA ' copy the state of pins 0..3 to the correct nib of inPw PAUSE 100 ' or whatever you do between enters of each digit NEXT ' now you've got BCD numbers as "digits" in the correct nib positions of inPw eeAddr = Passwords ' otherwise point eeaddr to start of data list DO READ eeAddr, WORD pw ' read the Word at eeaddr into pw IF pw = $FFFF THEN EXIT ' is the Word $FFFF? if so, then list is over, you are done, exit the loop IF pw = inPw THEN ' does password from list match what was input? DEBUG CLS, "Yes, that is a correct password", CR ' yes, debug that it's good HIGH 15 ' set pin high PAUSE 1000 ' wait 1 second LOW 15 ' set pin low EXIT ' exit the loop ELSE ' password did not match, so... eeAddr = eeAddr + 1 ' point to next byte in the data list ENDIF LOOP ' and check the next byte GOTO Main ' list ended or password match was found, so loop is over, start again▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 1/25/2008 4:54:54 AM GMT
[noparse]:D[/noparse]
Dan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 + 1 = 10 Base 2
2 + 2 = 10 Base 4
3 + 3 = 10 Base 6
4 + 4 = 10 Base 8
5 + 5 = 10 Base 10