Shop OBEX P1 Docs P2 Docs Learn Events
How can I get "Button" workspace value to hold and be stred in a portion of scr — Parallax Forums

How can I get "Button" workspace value to hold and be stred in a portion of scr

Capt. QuirkCapt. Quirk Posts: 872
edited 2009-09-03 00:40 in BASIC Stamp
The "workspace" value keeps resetting back to zero, every time I release the button. (like it supposed to, I am trying to save the value before it resets)

I am using a BS2p-40 and the AUX i/o pins to monitor four buttons on my PDB.

I am trying to enter a number that represents·kilograms. Then store the·number in my scratchpad ram and incorporate it into my program. I have read the manual and Dr Tracey Allen's site. The commands work fine for branching, but if it can "auto-repeat" I need to save that value.

Any suggestions would be helpful

Thanks

Bill

Post Edited (Capt. Quirk) : 8/31/2009 3:32:20 AM GMT

Comments

  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2009-09-01 05:32
    DO·········································································· ' Only works within a loop
    · AUXIO··································································· ' Turn on pins
    · PAUSE 100
    · BUTTON Button1, 0, 255, 250, w, 1, Value_Increase·· ' If pin goes low, branch to
    ·············································································· ' Value_Increase:

    Value_Increase:······················································· ' I would much rather make this a
    ··············································································· ' Subroutine
    · DO WHILE (Button1 < 1)
    ····· j = j + 1
    ····· DEBUG DEC j
    ····· PAUSE 500··························································· ' Slow down the loop
    ····· char = LcdLine1 + 12
    ····· GOSUB LCD_Command·········································· ' pins return to MAINIO
    ····· value = j
    ····· width = 3
    ····· GOSUB LCD_Put_RJ_Value
    ····· AUXIO···························································· ·' Must reset pins to AUXIO
    ····· PAUSE 100······················································· ' before next BUTTON command
    · LOOP

    ·BUTTON Button2, 0, 255, 55, w, 1, Value_Decrease

    Value_Decrease:
    · DO WHILE (BUTTON2 < 1)
    ····· j = j - 1
    ····· DEBUG DEC j
    ····· PAUSE 500
    ····· char = LcdLine1 + 12
    ····· GOSUB LCD_Command
    ····· value = j
    ····· width = 3
    ····· GOSUB LCD_Put_RJ_Value
    ····· AUXIO
    ····· PAUSE 100
    · LOOP

    · BUTTON Button3, 0, 255, 255, w, 1, Value_Select

    Value_Select:
    · PUT 1, j·································································· ' Put j in scratchpad ram
    · BUTTON Button4, 0, 255, 255, w, 1, Menu_Variables

    LOOP UNTIL i = -10···················································· ' Must BRANCH out of LOOP

    This works, but the WORKSPACE value "w" Does absolutely nothing. I would also like to make these Branches into subroutines, but when I do, the program keeps getting caught in continual loops and doesn’t return to the Buttons loop.



    I would much rather the program look more like this, and be able to PUT "w" into ScratchPad ram


    · AUXIO
    · PAUSE 100
    DO
    · BUTTON Button1, 0, 225, 255, w, 1, Menu_Mass
    · BUTTON Button2, 0, 255, 255, w, 1, Menu_Humidity
    · BUTTON Button3, 0, 255, 255, w, 1, Menu_BarrometricPressure
    · BUTTON Button4, 0, 255, 255, w, 1, Menu_Main
    LOOP UNTIL i = -10

    I think I would be better to Not use Button at all, and reduce it to this:

    Value_Decrease:
    · DO WHILE (BUTTON2 < 1)
    ····· j = j - 1
    ····· DEBUG DEC j
    ····· PAUSE 500
    ····· char = LcdLine1 + 12
    ····· GOSUB LCD_Command
    ····· value = j
    ····· width = 3
    ····· GOSUB LCD_Put_RJ_Value
    ····· AUXIO
    ····· PAUSE 100
    · LOOP
    Post Edited (Capt. Quirk) : 9/1/2009 5:40:10 PM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-09-03 00:40
    You may want to look at this [font=Tahoma,Bold size=2][font=Tahoma,Bold size=2]

    Program: SW21-EX14-Debounce.BS2· Page 95 of the Stamp Works book

    But I will try this routine and see how this work I do now have a PDB

    [/font][/font]
    When I want do this

    DO
    · BUTTON Button, 0, 225, 255, w, 1, Menu_Mass
    · BUTTON Button, 0, 255, 255, w, 1, Menu_Humidity
    · BUTTON Button, 0, 255, 255, w, 1, Menu_BarrometricPressure
    · BUTTON Button, 0, 255, 255, w, 1, Menu_Main LOOP UNTIL i = -10


    Why not try this


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    PickOne:

    DO

    IF IN1 = 1 THEN
    gosub Menu_Mass
    ELSE
    IF IN2 = 1 THEN
    GOSUB Menu_Humidity
    ELSE
    IF IN3 = 1 THEN
    GOSUB Menu_BarrometricPressure
    ELSE
    IF IN3 = 1 THEN
    GOSUB Menu_Main

    ENDIF
    ENDIF
    ENDIF
    ENDIF

    LOOP

    Menu_Mass:
    DO
    ' your code
    LOOP
    RETURN

    Menu_Humidity:
    DO
    LOOP
    RETURN

    Menu_BarrometricPressure:

    DO

    LOOP

    RETURN

    Menu_Main:

    DO

    LOOP

    RETURN

    OR this

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    BT1·· PIN· 1
    BT2·· PIN· 2
    BT3·· PIN· 3
    BT4·· PIN· 4

    cntr· VAR Byte··························· · '· VAR To a word

    '· cntr = cntr + 1 * BT1················ ·' >> This one is used IF the OUTPUT = 1
    '· IF (cntr = 300) THEN EXIT
    '
    '· cntr = cntr + 1 * (1 - BT1)········· ·' >> This one is used if the output = 0
    '· IF (cntr = 300) THEN EXIT

    PickOne:

    ·DO

    cntr = cntr + 1 * BT1
    IF (cntr = 10) THEN
    GOSUB Menu_Mass
    ELSE
    ·cntr = cntr + 1 * BT2
    · IF (cntr = 10) THEN
    GOSUB Menu_Humidity
    ELSE
    ·cntr = cntr + 1 * BT3
    · IF (cntr = 10) THEN
    GOSUB Menu_BarrometricPressure
    ELSE
    ·cntr = cntr + 1 * BT1
    · IF (cntr = 10) THEN
    GOSUB Menu_Main

    ENDIF
    ENDIF
    ENDIF
    ENDIF

    LOOP

    Menu_Mass:
    DO
    ' your code
    LOOP
    RETURN

    Menu_Humidity:
    DO
    LOOP
    RETURN

    Menu_BarrometricPressure:
    DO
    LOOP
    RETURN

    Menu_Main:
    DO
    LOOP
    RETURN

    The second one is different in that you set how long you must hold the button before it goes to which every routine you want it to
    which is the CNTR = time that you want in loops

    I hope this helps


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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 9/3/2009 1:25:24 AM GMT
Sign In or Register to comment.