keypad and arrays

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
kirstom14
Posts: 40
Joined: Thu Nov 15, 2007 9:13 am
Contact:

keypad and arrays

Post by kirstom14 »

Hi,
I am trying to read 8 consecutive numbers from a keypad, and then compare them to a variable which is made up from 8 numbers. Like a digital lock system.
But I am having trouble to enter the inputted number into one array (after converting each variable to string) and compare them to a string variable having
8 numbers stored in it.

How can I do it??

Thanks very much
tomcat14

User avatar
Benj
Matrix Staff
Posts: 14837
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: keypad and arrays

Post by Benj »

Hello

The file TUT_32 available from the Flowcode v3/Examples directory should be a good start for you. Basically it is a password input and validation example. You should then be able to switch the switch component for a keypad and take it from there.

kirstom14
Posts: 40
Joined: Thu Nov 15, 2007 9:13 am
Contact:

Re: keypad and arrays

Post by kirstom14 »

Hi,
Sorry if I am asking again, But I cannot understand how to adopt the code in Tut_32 to a keypad, as there you are always incrementing the current_char according to the switch pressed. I am having some difficulty as the keypad is only reading a 255!!

Thanks again
tomcat14

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8874
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: keypad and arrays

Post by medelec35 »

This might help. This is not my work but it is one of the projects from Microcontroller Systems Engineering book by Bert van Dam( Great book available from Matrix Multimedia or their distributors).
All this flowchart does is compare 4 numbers. If all 4 numbers are correct, Port A0 goes high for a set time.
This is a cleaver more efficient way because it does not involve any strings.
I have adapted code for 8 numbers instead of 4. The # key allows you to re-enter the 8 numbers.
This code is meant for a starting point for you. It may not be 100% what your after, just post any questions / issues or requirements and I'm sure we can help.
Attachments
doorbell.fcf
(11.5 KiB) Downloaded 537 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: 8874
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: keypad and arrays

Post by medelec35 »

Re: Keypad reading 255.
If you read keypad you only get 255 when no keys are pressed. If a key is pressed and you read 255, then key i/p routine is perhaps not assigned to variable you are reading?
If a problem with flowchart you have, then if you post it, then I can look at it for you.
Going back to your original posting: I'm sure you are aware the max Value of Int =32000.
So I believe your option would be to have an array of 8. then have a string (STRING1) which has all the arrays in the correct order. When each number is entered on keypad, that is converted to a string (STRING2). Then use mid$() function to individually compare STRING2 with a single char of STRING1 at a time.
I'm a bit push for time, but if I get the chance will create and post a flowchart that operates in the described manner.
Martin

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

kirstom14
Posts: 40
Joined: Thu Nov 15, 2007 9:13 am
Contact:

Re: keypad and arrays

Post by kirstom14 »

Hi,

Thanks for the reply. The attachment gave me, a very good start. The concept that I was using was pretty much the same,
but I was using the string arrays wrongly, so I adjusted my program to use bytes instead of strings, and it worked fine.

Thanks again for the great help
tomcat14

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8874
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: keypad and arrays

Post by medelec35 »

8) That's great!, glad you got a flowchart which is working fine. Thank you for letting us know.
A Couple of things.
1) I have left the simulation speed on a low setting, so I can watch the variables, so if keypad seems a bit unresponsive, just whack simulation speed back up.
2) I gave a figure of integer having a maximum value of 32000. I was just rounding down, to be on the safe side. The actual figure is 32767. Because it is signed, int can go as low as -32768
Martin

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

RobOnk
Posts: 37
Joined: Mon Jan 11, 2010 12:16 am
Contact:

Re: keypad and arrays

Post by RobOnk »

A different array question;

I'm trying to acquire a three digit number to use in a calculation.
I used an array namely (degcalc[2] to collect the numbers from a keypad. I understand that these are three individual numbers stored in a variable of the same name. My question is how would I go about converting these three digits into one number to use in a calculation? For example digits 1,2,3 entered converted to 1 hundred and twenty three. see file attached.

Thanks, Rob
Attachments
degree convert.fcf
(8 KiB) Downloaded 328 times

User avatar
Benj
Matrix Staff
Posts: 14837
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: keypad and arrays

Post by Benj »

Hello Rob,

What about the following.

INT variable Calc.
INT variable Temp.

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8874
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: keypad and arrays

Post by medelec35 »

Hello Rob.
The file you posted was intended for a different application to what you require.
So I have adapted it (using flowcode V4) so if you enter a three digit number e.g 356 then result will be three hundred and fifty six.
Just press # on keypad when all thee numbers are entered.
You can can press * on the keypad at any time to start again.
Hope this is useful to you.
Attachments
degree convertV2.fcf
(10 KiB) Downloaded 356 times
Martin

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

RobOnk
Posts: 37
Joined: Mon Jan 11, 2010 12:16 am
Contact:

Re: keypad and arrays

Post by RobOnk »

Wow thanks!
A bit scary how you could read my mind as I didn't think I relayed what I was trying to do very well.

After a quick look and reading your description though it looks right on.
Thanks again, Rob

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8874
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: keypad and arrays

Post by medelec35 »

Your welcome. Glad it what you are after. Thank you for letting us know.
Martin

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

RobOnk
Posts: 37
Joined: Mon Jan 11, 2010 12:16 am
Contact:

Re: keypad and arrays

Post by RobOnk »

Hello,
I hope I attached the correct file....

A slightly modified version of this small simple program to convert degrees C into degrees F and visa versa.
Works fine on the computer but the calculation gets all messed up in real life (on the board).
Maybe it has something to do with the way the micro performs calculations?

Help, Rob
Attachments
degree convertV2 rob.fcf
(12.5 KiB) Downloaded 253 times

User avatar
Benj
Matrix Staff
Posts: 14837
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: keypad and arrays

Post by Benj »

Hi Rob,

It could be down to calculation lines such as this.

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

Maybe something like this would ensure that the calculations are being processed in the correct order.

Result = ((degcalc[0]*100) + (degcalc[1] * 10)) + degcalc[2]

Another cause of the problems is this.

Result = Result*(5/9)

Result is a INT type variable which means it can only be 0,1,2 etc. Therefore your calculation is resulting in Result = 0.

If you want to do calculations like this then you will need to use Float variables and use the floating point calculation functions available from the calculatios icon functions window.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8874
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: keypad and arrays

Post by medelec35 »

Hello Rob.
I have just changed your calculations slightly. See if this works for you.
Attachments
degree convertV2 rob.fcf
(12.5 KiB) Downloaded 304 times
Martin

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

RobOnk
Posts: 37
Joined: Mon Jan 11, 2010 12:16 am
Contact:

Re: keypad and arrays

Post by RobOnk »

Thanks again, I will give it a shot.
Rob :P

Post Reply