Manipulating keypad presses


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2008
    Posts
    52

    Default Manipulating keypad presses

    Hello:

    I am scanning a keyad and am receiving and converting the rows and columns to numbers. I am wanting to display the numbers from 0 to 360 on an LCD. It is working as I am using a for next loop to put the key presses into an array. I then multiply the first one by a hundred and so on. But, if I only enter a 2 digit number I have to lead it with a zero, Is there and easier way?

    Let me clarify this a little: I actually want to save say the number 320 in a variable after getting it from a keypad one press at a time and use it to control PWM cycles.

    Thanks, Don
    Last edited by dbachman; - 3rd January 2011 at 03:52.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Not sure to follow you but let's see.
    Code:
    ' Pseudo, for entertainement only or you'll be changed to a pumpkin at midnight
    Number=0
    Duty=0
    
    DoIt:
    LCDOUT $FE,1,"Number=",dec number Call KeyPad Routine IF KeyPad Scan routine Return a valid single decimal number entry Then
    Number = (Number *10) + KeyPadValue ' ' Some test to make sure you're in the max duty range ' GOTO DoIt ENDIF
    If Number !=Duty then
    Duty=Number HPWM 1,freq, Number endif
    GOTO DoIt
    Last edited by mister_e; - 3rd January 2011 at 04:22.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Oct 2008
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Mister_E

    Actually I am using your keypad scan routine.

    I am using a
    for x = 1 to 3
    gosub getkey
    array[x] = keypress
    next x
    total = array[x]*100 + array[x]*10 + array[x]

    But I have to make 3 entries in the array to satisfy the for next loop. So I have to use a leading zero if I enter anything less than 100. It works fine its just a pain.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    No you don't need, read my example above again, there's this IF THEN line after the Keypad reading...







    </pre>
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Oct 2008
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Steve,

    I guess I am still a little confused .

    If I go get a keypress and I just pushed 3 for example. How is that moved three decimal places (multiplied by a 100) and then added to the next keypress which must be moved over 2 places?
    I will study it some more but I am not "seeing" it yet.

    Thanks for taking the time.

    Don

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    How many key do you have on your Keypad? any left to be used as "enter" key?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Oct 2008
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    I have 16 keys. I am using "E" or I think #14 as enter now for another routine.

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    A small hint
    Code:
    if keypress<=9 then 
    Number=(Number*10)+KeyPress GOTO DoIt Endif

    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    Join Date
    Oct 2008
    Posts
    52


    Did you find this post helpful? Yes | No

    Red face Thanks

    I finally got it........

    Thanks Steve

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts