Basic Keypad - LCD Four Digit Door Lock.

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Basic Keypad - LCD Four Digit Door Lock.

Post by medelec35 »

Have adapted the Flowcode I posted here: http://matrixmultimedia.com/mmforums/vi ... f=5&t=7140 to create a basic 4 digit code door lock.

Here is a challenge: See if you can edit the Flowcode so If you make a mistake in entering 1 digit. you can re-enter that digit.
By following and learning how a flowcode routine works, then altering to acheive desired results, I beleive is a great way of learning!

I have deliberately created a Flowcode in which re-entering a digit is easily achievable.
For Beginners: See how arrays are used, and how several arrays are converted to an integer and compared with another integer.
Attachments
Door Lock.fcf
(14 KiB) Downloaded 1848 times
Martin

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by Spanish_dude »

I'm using flowcode v3 and I can't open the file so it would be great if you could make an v3 file or attach the C code.

Thx anyway for the program :mrgreen:

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by medelec35 »

I wil create a V3 version and hopfully will post it tomorrow (Thursday EVE).
Here is C file.
Attachments
Door Lock.c
(21.68 KiB) Downloaded 993 times
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by medelec35 »

Sorry been a bit busy. So here is V3 version of LCD Four Digit Lock.
Attachments
Door Lock for FlowcodeV3.fcf
(12 KiB) Downloaded 1183 times
Martin

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by Spanish_dude »

Hi medelec35,

Thx for the flowcode file.

I just have one thing to say.

Why are you using an array to store the value of the keypad ?

You could do it like this :

Code: Select all

//...
short private_code = 1234;
short user_code = 0;
char key = 0;
//...
//if key is pressed
user_code *= 10 + key;
//...
Regards,

Nicolas L.F.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by medelec35 »

Hello Nicolas.
You are welcome.
The reason for storing value of keypad is because a Flowcode user wanted to press several keys e.g 1 2 3, and convert the keypad presses into an integer i.e one hundred and twenty three. See http://www.matrixmultimedia.com/mmforum ... f=5&t=7140. Since I already had that flowcode stored, I thought I would use it to make an electronic door lock.
Also keypad was stored as an array, so string conversion is not required. Thus reducing the overall size and memory usage. Also if you store as an array, you can easily manipulate and say delete the 2nd from last entry for correction.
Martin

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by Spanish_dude »

Hi medelec,

I'm not sure about reducing the size of the memory using an array.
If I'm correct, an integer is 4 bytes and a char is 1 byte (so an array of 4 chars = 4 bytes).
Only if you are willing to use a password with 3 or less digits, it will reduce the size of the memory (a little :P).

But I do see the point of using an array.
-It ts easy to change each variable in array
-Because an integer only goes to ~32000 your password can not have more than 4 digits. With an array of chars you could have (much) more than 4 digits.

Thx anyway :mrgreen:

Nicolas L.F.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by medelec35 »

I believe the size reduction due to the fact that string conversion is not required. So that negates the requirement of both string variables and integers. But I could be wrong.
As using integer opposed to arrays. Yes you are correct, that would simplify compared to arrays. As previously stated This article was derived from another post, for someone who wanted to store each key-press, and use them to form a function. Also someone else wanted to store and compare a number with more than 5 digits, so its back to string or arrays.
Martin

donald
Posts: 74
Joined: Tue Feb 14, 2012 5:17 pm
Been thanked: 3 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by donald »

Hi,
How do I change the code of the keyboard ?
It can give you an example flowchart ?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by medelec35 »

Hi donald,
When you open flowchart, you will see:
Change code.png
(9.6 KiB) Downloaded 18512 times
so to change code just alter the 1234

If you have got EEPROM on your target device, then you could have a master key or current pw and to change pw by entering new pw with keypad.
Then new pw can be saved on EEPROM
The reason for a master key is the pw may have been changed, but new pw could be forgotten.
Master key can be left unchanged.

I will probably alter flowchart to do that, when I get some time spare on my hands.

Martin
Martin

donald
Posts: 74
Joined: Tue Feb 14, 2012 5:17 pm
Been thanked: 3 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by donald »

I understand a bit, but for me it is hard, because I don't know what to write and to add to flowchart.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by Benj »

Hi Donald,

There is a free "introduction to micros" course available from here designed to help get you started with Flowcode and programming.

http://www.matrixmultimedia.com/lc_index.php?p=24

donald
Posts: 74
Joined: Tue Feb 14, 2012 5:17 pm
Been thanked: 3 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by donald »

Hi everybody,
Thank You Martin and Ben, I have added to the bill Martin a protection for the three tests wrong to enter the code.
In the first two codes wrong the system will generate a warning signal and short acoustic optical (200ms), on the third
attempt will generate an alarm signal for 5s or more. I have a question, where I had to look to learn about some
instructions that I must write to them, for example:

Result = degcalc[0]*1000+degcalc[1]*100+degcalc[2]*10+degcalc[3]

In addition to Flowcode, must learn a different development environment ?
Thank you very much !

Sam
Attachments
add.png
(49.48 KiB) Downloaded 18401 times
panel.png
(15.35 KiB) Downloaded 18425 times

iron_zombie
Posts: 4
Joined: Fri Oct 18, 2013 11:04 am
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by iron_zombie »

Hi.

Thanks to the people doing the programme. Is it possible to do one so that multiple passcodes could be entered (approx 20)?

Would someone be able to do that?

Thanks

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by dazz »

Hi iron zombie

Have a go yourself and when you get stuck post a flowchart and someone will help you out, also heavily comment you flowchart if you can as it will also help others to help you if they can see what your trying to do

Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

iron_zombie
Posts: 4
Joined: Fri Oct 18, 2013 11:04 am
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by iron_zombie »

Hi, I take it it's not as simple as just modifying the existing programme posted is it? I tried just adding more pass codes to it but when I do that, only the last pass code entered unlocks the door.

My programming knowledge is basically non-existent so I wouldn't know where to start really to do my own programme.

Thanks for your response.

iron_zombie
Posts: 4
Joined: Fri Oct 18, 2013 11:04 am
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by iron_zombie »

Hi, I've had a go at editing the programme with more than one access code by using a macros however all it does is register the first macro. So if I try entering the other codes in the other three macros (e.g. 2345, 3456 or 4567) it still says wrong code. Can anyone help?

Also I doubt using the macros is the most efficient use of the chip either as it will likely take up a lot of memory. Is it possible to have multiple pass codes in some sort of array and then the programme calls on that array to allow entry?

Thanks.
Attachments
Door Lock 16F877A 4 pass code macro.fcf
(60.21 KiB) Downloaded 566 times

iron_zombie
Posts: 4
Joined: Fri Oct 18, 2013 11:04 am
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by iron_zombie »

Apologies for the double post. I've worked on it a bit more. I've managed to sort an array out and have it so that there are twenty possible numbers plus another ten left to enable them to be edited at a later date if needed (these 10 are entered as 0000 which i've set to keep the door locked).

My problem now is though that the last two real pass codes (i.e. Code[18] and Code [19] in the array) say wrong code when entered. All the other passcodes (Code[0] to Code[17]) work, but for some reason Code[18] and Code[19] don't.

Anyone know where I'm going wrong?

I forgot to mention I'm using flowcode 5 by the way.

Thanks
Attachments
Door Lock 16F877A - Working multiple access code plus 0000 = no entry 30 codes - last two dont work.fcf
(21.51 KiB) Downloaded 465 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by Benj »

Hello,

The macros have while 1 loops which means that they will never exit so your program will only ever stay in macro 1.

Here is a version of the program that uses an array to store the keys, not tested it but it should work.
Door Lock 16F877A 4 pass codes.fcf
(18.98 KiB) Downloaded 574 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by Benj »

Anyone know where I'm going wrong?
Have a look at my example, I use a loop rather then the large if statement you have. My guess is that the loop approach will be more reliable for lots of keys and allows you to easily see which code provided the unlock.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by medelec35 »

Not seen Bens example, so this maybe a similar approach.
Sorry if it is Ben, as its the way I would tackle this issue.

Martin
Attachments
Door Lock 16F877A - Working multiple access code plus 0000 V2.fcf
(20.92 KiB) Downloaded 548 times
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by medelec35 »

Just had a look at Ben's example, and mine is totally different.
With the flowchart on my above post, its possible to have up to 255 different past codes by changing:

(Count = 30) || (Result = Code[Count])
to
(Count = 254) || (Result = Code[Count])

Also you will need to increase size of array of course :)

Martin
Martin

obertelli7
Posts: 2
Joined: Fri Dec 06, 2013 3:19 pm
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by obertelli7 »

Hi
I have a similar program to this, however I have installed a switch before a code can be entered.
I'm having problems in getting the switch to reset to a low state again without manually pressing the switch again. This enables the user to enter another code.
Is there a way to automatically reset this in the program so that the user can't enter multiple codes without pressing the switch again?
Any help would be great,
Thanks!

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by medelec35 »

Hi obertelli7,
Welcome ot the forums.
If you would like to post your flowchart, I can take a look at it for you.

Martin
Martin

obertelli7
Posts: 2
Joined: Fri Dec 06, 2013 3:19 pm
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Post by obertelli7 »

For some reason I can't attach any files or images?

Post Reply