keypad control of stepper
lardom
Posts: 1,659
· 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 ····························································································
······················································ ·PRI Keybuf|code··········
·· ······················································ ··if key == 11····························· {11 is the # key}
····························································· ·tester·
····························································code· := code * 10 + key
· ························································ ·distance := code ····························································································
Comments
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Imagination is more important than knowledge..." Albert Einstein
· 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.
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