Shop OBEX P1 Docs P2 Docs Learn Events
Need help with a Select and Enter type menu — Parallax Forums

Need help with a Select and Enter type menu

ihmechihmech Posts: 179
edited 2009-05-30 20:42 in BASIC Stamp
I have been working on building a shop tool for use at my workplace.· I have been tinkering with electronics for the past 15yrs, but I am new to the Basic Stamp and programing, I'm teaching myself and trying to develop a tool at the same time.· My biggest problem is that I have not been able to create a simple menu.· I want a menu that I can display on an LCD, but I can't get the menu part down.· The menu I want works like this:· "Press select to choose machine"· Pressing the·select button will change the menu between "Machine_A and Machine_B" and pressing enter for "Machine_A or B will·start the program and use preset values for the machine selected.· I also need to be able to add more than two options in the future for new machine models.· Any help would greatly be appriciated.· Thanks!

Post Edited (ihmech) : 5/27/2009 2:01:45 AM GMT

Comments

  • rixterrixter Posts: 95
    edited 2009-05-27 02:06
    ihmech,

    What I did was to have a couple of push buttons to the right side of a 4x20 LCD and I displayed on the LCD the menu choices with an arrow pointing to the button to press. Here is an example:

    Run Program One --->
    Run Program Two --->
    Run Program Three -->
    Run Program Four -->

    The code in your program will loop through and check for the pressing of any of these buttons and branch to the appropriate code in your program (or slot in your BS2 if so equipped). In your case, you may need a hierarchy of menu screens. So for example pressing button one would jump to code that displays another menu on the LCD that applies to Machine A in your case. Push buttons can of course be "re-used" in the sense that the top button is selecting a machine in the first level of the menu system and may be used to turn that machine on in menu level two.

    Scanning for pressing of buttons is not difficult and I can provide examples of what I did there if you want.

    I hope this helps.

    Rick
  • ihmechihmech Posts: 179
    edited 2009-05-27 11:25
    Any help with code would be great! I have been trying to use debouncing multiple inputs with no luck. I kept having trouble with the BS2 reading the two pushbuttons and that is why I was trying to use the debouncing code example. Thank you!
  • rixterrixter Posts: 95
    edited 2009-05-27 17:09
    You can study the BUTTON command to understand more about debouncing. There is also info there on wiring a switch. I use the pulldown method where downstate produces a 1. I don't use the BUTTON command for my purposes because it wasn't required and it takes up some overhead. The loop that checks for the pressing of a button for a menu is going to be tight and you are going to jump to program code the instant it senses a pressing of a button. There shouldn't be any need to check for duration of the press. If your project requires you to monitor a button press while other processes are occurring, that is a different story. But you should be ok to work with something simpler for a menu. In this example below I have two pushbutton switches attached to pins 1 and 2 on the Stamp. The code loops back and forth between checking for a press on either button. As long as no button is pressed, the loop continues infinitely. Once a button is pressed, it branches to the appropriate code segment in your program and returns to the menu at the end.

    Rick


    :MENU

    ; display menu to the LCD here...

    menubutton1: ' top button
    IF IN1=0 THEN GOTO menubutton2
    GOTO CODESEG1 ; goto part of program you want to run when button 1 is pressed

    menubutton2: ' bottom button
    IF IN2=0 THEN GOTO menubutton1
    GOTO CODESEG2 ; goto part of program you want to run when button 2 is pressed

    :CODESEG1
    ...
    ...
    GOTO MENU

    :CODESEG2
    ...
    ...
    GOTO MENU
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-28 03:02
    Try this little Routine and see if this will work for you

    chg············ PIN···· 1·············· 'This is your input pin

    cntr··········· VAR···· BYTE


    ············ '·One routine is IN1 = 1 and the other routine is for IN1 = 0


    ············ ·' I have use this little Routine a few time when go to a different· routine using a switch

    Do

    cntr = cntr + 1 * Chg
    IF (cntr = 5) THEN···· ·' Or ·EXIT··· cntr = How Long you want to hold the button before it gose to what ever routine you want it to go to
    DEBUG· ? Chg··, CR, ?·cntr····················· ' one nice thing about this routine is if your input dose not stay ethier a 1 or 0 for the hole count
    ·ENDIF········································ ' The Cntr counter gose back to " 0 "

    cntr = cntr + 1 * (1 - Chg)
    ··· IF (cntr = 5) THEN

    DEBUG· ? Chg, CR, ?Cntr
    ENDIF


    LOOP

    I hope this helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • ihmechihmech Posts: 179
    edited 2009-05-28 16:22
    So far I have a menu made up that works very well and I am quite pleased with it. ·I'm still working some small bugs out of it though.· I'm·pretty stuborn and like to figure thinks out for my self...can't learn unless you fail...If I keep having trouble, I will post the code I have wrote so far for the menu.· Thank you all for your help!lol.gif·
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-28 22:52
    ihmech

    ·I'm still working some small bugs out of it though. I'm·pretty stuborn and like to figure thinks out for my self...can't learn unless you fail.·<<<..........>>>> I know what you mean

    When you have all of the bug work out of you code routines
    Would you Please Post your Project in the Completed Project

    Also if you need any help with your code feel free to ask


    Thank You

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/28/2009 10:58:50 PM GMT
  • ihmechihmech Posts: 179
    edited 2009-05-30 20:42
    I finally had time to sit down and work on my menu. I just got two small bugs worked out with the program and it works great! Thanks everyone for all of your help!
Sign In or Register to comment.