Shop OBEX P1 Docs P2 Docs Learn Events
Problem with creating menus — Parallax Forums

Problem with creating menus

W9GFOW9GFO Posts: 4,010
edited 2009-05-10 17:29 in Propeller 1
I spent a bit of time yesterday figuring out how to make a menu system to select from and run several different programs. I think I got it but if anyone knows of some sample code I could look at, it would be appreciated.

Now my problem. It seems so simple but it doesn't work.

First there is a "Hello" screen for 3 seconds, then it (should) goes to another screen indefinitely while waiting for button input. Instead, after three seconds the screen clears and stays blank until I push a button.

I can't see why the code within the 'while' loop is not being run. When a button is pushed, it runs the code within the 'while' loop - forever. I expected a ButtonState change to exit the 'while' loop.

Rich H

  PUB Init


  LCD.init(LCD_Pin, LCD_Baud, LCD_Lines)                ' Initialize LCD Object
  LCD.cursor(0)                                         ' Turn Off Cursor
  LCD.backlight(true)                                   ' Turn On Backlight

  LCD.cls
  LCD.str(string("Hello", 13, "3 sec delay"))

  RC.Init(RC_Pin)
  servo.start
  waitcnt(clkfreq*3 + cnt)
  LCD.cls

  repeat while ButtonState == %000
    LCD.str(string("Push to continue", 13, "Volts = "))
    waitcnt(clkfreq/10 + cnt)

  program := 1
  Select 

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-10 17:12
    What's ButtonState?
  • W9GFOW9GFO Posts: 4,010
    edited 2009-05-10 17:29
    Mike Green said...
    What's ButtonState?

    Aha, see? That's why I asked. It only took two words and now I found the problem!

    To answer the question - ButtonState monitors the three push buttons and returns a number based on which one(s) is(are) pressed. Trouble is, it also has a 'while' loop!


    PUB ButtonState : result | t1, dur
    
      ina[noparse][[/noparse]Bt1..Bt3]~
    
      repeat while ina[noparse][[/noparse]Bt1..Bt3] == %000                     ' stay here until a button is pressed
          t1 := cnt
    
      repeat while ina[noparse][[/noparse]Bt1..Bt3] <> %000                      ' stay here until a button is pressed for at least 1/4 second
          dur := cnt - t1
          if dur => clkfreq*4
            result := ina[noparse][[/noparse]Bt1..Bt3]
          waitcnt(clkfreq/30 + cnt)
    
    
    



    Thanks Mike, I can now move forward.

    Rich H
Sign In or Register to comment.