KEYPAD TO LCD ENTRY

Any general or miscellaneous queries that do not fit into the other forum catagories

Moderators: Benj, Mods

Post Reply
moxy
Posts: 14
Joined: Thu Nov 20, 2008 4:42 pm
Contact:

KEYPAD TO LCD ENTRY

Post by moxy »

Hi, I am wanting to write code to enter 3 digits to lcd and then do some calculations on the resulting number. The aim is to enter a number of divisions for a dividing head and then calculate how many steps tp output to a single pin. I have the maths figured and just need to get the three digits entered and manipulable.
Thanks in advance
Les

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: KEYPAD TO LCD ENTRY

Post by medelec35 »

take a look here: http://www.matrixmultimedia.com/mmforum ... f=5&t=7140
Can be changed for 3 numbers easily.
If you search for keypad there will be other examples around.

Note to Matrix staff: Not receiving any email notifications, is this just my account or a global issue?
If can be sorted would appreciate it.
Thank you.
Martin

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: KEYPAD TO LCD ENTRY

Post by Steve »

Hi Medelec,

I'm receiving email notifications when someone replies to a topic I have ticked. Are they perhaps ending up in your junk email folder? We did update the software the other week, and there may be issues around this.

I'll also send you an email via the forum now just for you to confirm that your email address is correct.

moxy
Posts: 14
Joined: Thu Nov 20, 2008 4:42 pm
Contact:

Re: KEYPAD TO LCD ENTRY

Post by moxy »

Hi medelec, Thanks for your reply, I have almost reached my goal but have the following problem. I can enter the 3 keys ok but the maths seems to be a random thing. The output pulsing is working fine but the calculation to convert the number of divisions to degrees ( I need to be able to go to about 4 dec places) and the degrees to pulses is moggy. Could you please check the code attached and advise? Maybe I'm asking too much of the PIC......
Attachments
div2.fcf
(16 KiB) Downloaded 446 times

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: KEYPAD TO LCD ENTRY

Post by medelec35 »

Hello moxy.
One area I believe you are going wrong with is string manipulation. Even if converting string to int or float etc, you should use the 'String Manipulation' box (click on 'Functions'), not the Calculation box.
if you place a string within a Calculation box then you will see the string variable with [] at the end. You definitely can't use function String_Variable[] = String_Variable[] = int_Variable within a calculation box. If i remember correctly, even if you use an index within[] you will be adding the ASCII int_Variable to the string?

Perhaps if you say how you intend on manipulation the maths to convert the 3 numbers entered on keypad into degrees (as my maths is not my strong point), with an example, I will see what I can do.
Martin

moxy
Posts: 14
Joined: Thu Nov 20, 2008 4:42 pm
Contact:

Re: KEYPAD TO LCD ENTRY

Post by moxy »

Hello Medelec, Thanks for your reply, The device I want to control is used on a milling machine to machine equally spaced cuts on a workpiece. Something like a gear wheel. As you have seen, I am having difficulty entering a 3 digit number, displaying it, and then doing some maths on it. This consists of dividing 360 by this result which will give me the degrees per movement (division) This, of course will vary with the amount of divisions that I have selected. Then I have to multiply the result by the amount of steps that my hardware needs to move 1 degree. It seems that I am not getting the number correctly into the chart. Hopefully this makes it a bit clearer.
Many thanks
Les

moxy
Posts: 14
Joined: Thu Nov 20, 2008 4:42 pm
Contact:

Re: KEYPAD TO LCD ENTRY

Post by moxy »

Hi Medelec, me again. I forgot to give you an example.
Suppose I need to make a gearwheel with 30 teeth. I would divide 360 by 30 to get the degrees per tooth, in this case 12. If my hardware takes 100 steps to move 1 degree I would multiply the 12 degrees by 100 which would give me a number of 1200 which I would output sequentially on a pin which would drive the stepper motor. Hope this make it a bit clearer.
Many thanks
Les

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: KEYPAD TO LCD ENTRY

Post by medelec35 »

Hello moxy.
I have completed the difficult bit for you. if you enter 030 on the key pad, then STEPSPER = 360 / STEPSPER * 100 = 1200. So your STEPSPER would be set at 1200. Just got to increase accuracy e.g if 153 is entered, then result will be 240 instead of 235. (require floating point maths like you can in V4) You can only get a maximum number of 255, if using byte. You needed to use Int which can go form -32768 to +32768
I have also made the keypad input routine shorter and slightly better. If a key is held, then the routind is paused until key is released. This is done so the same number is not entered more than once due to fast keypad scan routine.
now you can keep entering different values (only 3 digits at any one time will be displayed), in case you make a mistake, then the final value will not be used until you press the # key. e.g you can enter 4567876546086 then # and only 086 will be displayed and used in calculations.
Note max value that can be entered is 360, due to the way maths is calculated in pic chips.(its a good job since you won't want more than 360 any way :P ).
The Most awkward thing was converting 3 digit string to a numeric value. In flowcode V4 it's very easy as there is a StringToInt() function. Wish there was one within V3.
Perhaps someone can post a better way than I have achieved it? Since I can only think of one way.
I will leave the rest for you to do.
One comment, You have not got any delay between your A0 going on and off. The switching will be to fast for your your hardware to cope with.
Hope this helps.
Attachments
div3.fcf
(13.5 KiB) Downloaded 483 times
Martin

moxy
Posts: 14
Joined: Thu Nov 20, 2008 4:42 pm
Contact:

Re: KEYPAD TO LCD ENTRY

Post by moxy »

Hi Medelec, You are a scholar and a gentleman,sir!!!!!!! Many thanks I will upgrade to Flowcode v 4 shortly.
Best regards
Les

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: KEYPAD TO LCD ENTRY

Post by medelec35 »

Thank you Les, and your welcome.
V4 is definitly worth getting. Since you have already got V3 u get V4 at 1/2 price (I think?) V4 can do so much more, not just the maths and conversion functions.
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: KEYPAD TO LCD ENTRY

Post by medelec35 »

@ Benj and Steve
I received my 1st notification email since forum upgrade, today
Thank you for sorting it out.
Ben I also sent you a pm on Friday 16th April at 2.51pm. Not a problem if you did not get time to read pm's. Just letting you know just in case you are not receiving pm's

Edit: false alarm. Not recevied anymore :cry:
Martin

Post Reply