Shop OBEX P1 Docs P2 Docs Learn Events
keypad control of stepper — Parallax Forums

keypad control of stepper

lardomlardom Posts: 1,659
edited 2010-02-23 00:17 in Propeller 1
· I·am translating a working Pbasic app that I wrote to Spin. I want to control the speed and distance of a stepper motor with a 4x4 keypad and display those values on an LCD.··My problem is that when·I press the # key, which I use as an enter button,·the same value gets copied to both 'distance' and 'speed'. I included a piece of code that passes a value to a PUB method I call "tester".·How can I·send a separate value to "speed"?

······················································ ·PRI Keybuf|code··········
·· ······················································ ··if key == 11····························· {11 is the # key}
····························································· ·tester·
····························································code· := code * 10 + key
· ························································ ·distance := code ····························································································

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-02-22 03:56
    How about showing "tester"?

    Why do you have "distance := code" in "Keybuf"? It's difficult to tell you what to do without more of your program. How about attaching the whole thing to a message (use the Post Reply button and the Attachment Manager).
  • Brian_BBrian_B Posts: 842
    edited 2010-02-22 04:05
    ·I don't know if this will help any,here is a keypad read program I did some time ago. I do have another version that stores the key presses until you hit "enter" ,but that one still has some bugs.



    Brian

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔





    "Imagination is more important than knowledge..." Albert Einstein
  • lardomlardom Posts: 1,659
    edited 2010-02-22 04:07
    Thanks for responding so quickly. I will attach the entire program in a day or so after I clean up the file. You guys are great.
  • lardomlardom Posts: 1,659
    edited 2010-02-22 17:27
    I've attached the necessary files minus most of the clutter. This is my third forum post and I'll try not to ask for help if I can help it because I get a big charge out of solving these problems myself. (Crossword puzzles don't do it for me.) When I completed my BS2 project I got depressed so I decided to jump back in and challenge myself·to a more feature rich Spin version·using less hardware.

    · My problem is that I can't figure out how to send separate values to variables "distance" and "speed" with one key. I want to use the # key on my 4x4 keypad as the enter key.
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2010-02-23 00:17
    I don't think you can do it with just one button, the program needs to know which you are trying to adjust. If you really wanted to use one button then I suppose you might use time, a long press on the # means distance a short hit speed. But better might be to have a button to press before entering the speed/distance

    A100#

    Might set speed 100

    B50#

    Might set distance to be 50.

    Or use one button to toggle what you are adjusting, that is quite a nice way to do it because you can add as many items as you like to a list and use the one button to scroll through them. You might also have a cancel button if you decide you don't actually want to press enter.

    Graham
Sign In or Register to comment.