Page 1 of 1

Negative number from keypad

Posted: Tue Apr 24, 2012 11:11 pm
by Bobw
I am playing around with the keypad trying to figure out how to pass a negative symbol to a variable.
IE: User wants to input -60. This should equal 3 key presses from the keypad. -, 6, 0
I am using a 4x4 key pad, and figuring the F key would be labeled - or (15) when pressed.
I think I figured out how to read a key press and pass it to one variable, and read a second key press and pass it to a second variable. But the negative symbol is kicking my brain.

I have found most of the examples for the key locks/door locks that have been posted on here.

Any Ideas?

Re: Negative number from keypad

Posted: Wed Apr 25, 2012 8:53 am
by JohnCrow
Hi Bob

Just a quick though, could you program it to use the ascii code for "-"

Re: Negative number from keypad

Posted: Wed Apr 25, 2012 2:31 pm
by Bobw
John,

I thought about that last night.
Need to input from -90 to 450.
Won't be able to play around with it till this weekend.
To bad there is not a FC app so I could play with it on my tablet.

Bob

Re: Negative number from keypad

Posted: Wed Apr 25, 2012 3:04 pm
by JohnCrow
Now thats a good idea
Flowcode for Android :wink: :D

Re: Negative number from keypad

Posted: Wed Apr 25, 2012 3:16 pm
by dazz
Try this should give you enough to get started use the f key in sim to get your symbol

a very quick way to get the decimal number for a key press, is to open a flowchart add a loop with a keypad macro in it, add a variable as the return byte in the macro, then in build option select 100 as a speed, then simulate simple add the variable you created then everytime you press a hey the number associated with that key is diplayed, to change say the f key use a decision branch as in my flowchrt , to get the hex value for the symbol you want displayed open windows calculater and set it to programmer mode (a good tip from either john crow or medelec was either or both) then looking at the ascii chart in the help files, simply type in the binary number for the symbol you want, click on the hex box incalc and use that number hth

Re: Negative number from keypad

Posted: Wed Apr 25, 2012 6:32 pm
by Bobw
Dazz,

Played around with your example a bit.
That may work.
Will have another go at it this weekend.
I thought about using go to satements in case the input needed to be erased (wrong key pressed)
Would give you an easy way to back up a step.

Thanks

Bob

Re: Negative number from keypad

Posted: Wed Apr 25, 2012 9:08 pm
by dazz
Hi if you look at one of medelecs door lock flowcharts theres one somewhere which shows how to deal with incorrect inputs. the one i posted is just a quick way to make a specific key show a - on a display, you could also map another key say the A key to maybe act as a backspace key for incorrect input hth

Re: Negative number from keypad

Posted: Wed Apr 25, 2012 10:06 pm
by medelec35
Hi Bob,
I have adapted a flowchart to allow you to enter -negative or positive numbers.
You can enter between 1 and 3 digits and minus can be used at any time. E.g
1
67
-4
-890
46-7
1-23
Take the last example.
If you enter 1-23 then result variable = -123
Neg Nums.png
(156.93 KiB) Downloaded 5239 times
E is to enter digits
C is to clear last entry

If I can think of a way to simplify it then I will.

Martin

Re: Negative number from keypad

Posted: Thu Apr 26, 2012 12:23 pm
by dazz
Martin silly question time, whats the reason for taking 48 from the keypad number

Re: Negative number from keypad

Posted: Thu Apr 26, 2012 12:45 pm
by wayne millard
Hi

I is because when you press the button 0 = 48 1 = 49 and so on so you need to take 48 from the result you get to get the number of the button you have pressed.

wayne

Re: Negative number from keypad

Posted: Thu Apr 26, 2012 12:54 pm
by dazz
cheers wayne

Re: Negative number from keypad

Posted: Thu Apr 26, 2012 1:10 pm
by medelec35
Not a silly question at all. In fact that is a good question!
I have not got V3 to check, but I believe it was Bert Van dam who did it that way.
the -48 just converted ASCII into the relevant number.
E.g number 1 is ASCII 49.
so 49-48 =1
I just kept it like that for people with FC3 load flowchart with free V5 and create their own V3.
Since I don't believe FC3 has GetKeypadNumber??
Will find out tonight :lol:
If I am wrong then there is no need to have used -48 at all.
However since V3 is years old now I will be stopping that method and just use GetKeypadNumber instead of
GetKeypadAscii

Martin

Edit: Just noticed a new post has been posted, so sorry if repeating any information.

Edit2, My memory is getting poor (Dam old age :lol: ) Flowcode3 does have GetKeypadNumber, so GetKeypadAscii could of been used
to send ASCII via rs232.
Anyway from now on I will revert to GetKeypadNumber!
Thanks Daz :)

Re: Negative number from keypad

Posted: Thu Apr 26, 2012 1:24 pm
by dazz
Ah got it as i used getkeypad number and didnt notice you used get ascii, but glad i asked as its good to know the differences between the two