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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3451 times
Contact:

Basic Keypad - LCD Four Digit Door Lock.

Postby medelec35 » Sun May 23, 2010 10:09 am

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 1478 times
These users thanked the author medelec35 for the post:
Drakkor (Tue Nov 12, 2013 2:31 am)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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.

Postby Spanish_dude » Wed Jun 16, 2010 7:17 pm

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:

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3451 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby medelec35 » Wed Jun 16, 2010 9:34 pm

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3451 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby medelec35 » Sat Jun 19, 2010 9:42 am

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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.

Postby Spanish_dude » Sat Jun 19, 2010 5:27 pm

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.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3451 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby medelec35 » Sat Jun 19, 2010 7:02 pm

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 viewtopic.php?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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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.

Postby Spanish_dude » Sun Jun 20, 2010 9:53 pm

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.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3451 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby medelec35 » Sun Jun 20, 2010 10:28 pm

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby donald » Sat Apr 07, 2012 10:05 am

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3451 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby medelec35 » Sat Apr 07, 2012 10:33 am

Hi donald,
When you open flowchart, you will see:
Change code.png
Change code.png (9.6 KiB) Viewed 17624 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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby donald » Sat Apr 07, 2012 10:49 am

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: 14371
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4447 times
Been thanked: 4150 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby Benj » Tue Apr 10, 2012 10:30 am

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.

Postby donald » Sat Apr 14, 2012 7:51 am

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
add.png (49.49 KiB) Viewed 17513 times
panel.png
panel.png (15.35 KiB) Viewed 17537 times
These users thanked the author donald for the post:
medelec35 (Wed Apr 25, 2012 7:07 am)
Rating: 5.26%
 

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

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby iron_zombie » Fri Oct 18, 2013 11:10 am

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: 514 times
Been thanked: 467 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby dazz » Fri Oct 18, 2013 7:20 pm

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.

Postby iron_zombie » Tue Oct 22, 2013 7:57 pm

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.

Postby iron_zombie » Fri Nov 15, 2013 11:12 am

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 389 times

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

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby iron_zombie » Fri Nov 15, 2013 12:05 pm

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 299 times

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

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby Benj » Fri Nov 15, 2013 12:06 pm

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 404 times

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

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby Benj » Fri Nov 15, 2013 12:11 pm

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.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3451 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby medelec35 » Fri Nov 15, 2013 2:33 pm

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 372 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3451 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby medelec35 » Fri Nov 15, 2013 7:33 pm

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby obertelli7 » Tue Dec 10, 2013 8:27 pm

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!

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3451 times
Contact:

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby medelec35 » Tue Dec 10, 2013 9:44 pm

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

Martin
These users thanked the author medelec35 for the post:
Benj (Tue Dec 10, 2013 11:46 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: Basic Keypad - LCD Four Digit Door Lock.

Postby obertelli7 » Wed Dec 11, 2013 1:19 pm

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