Shop OBEX P1 Docs P2 Docs Learn Events
Does each instance of 'BUTTON' need a separate workspace? — Parallax Forums

Does each instance of 'BUTTON' need a separate workspace?

cthomascthomas Posts: 17
edited 2009-09-04 22:19 in BASIC Stamp
Just wondering...I don't need to debounce my pushbuttons and am wondering about using multiple instances of BUTTON.
It's not clear from the command definition, if each BUTTON command needs it's own workspace or if 'workspace' could be shared.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-09-01 20:14
    Yes, it does.· For this reason it is often desirable to use a different method of reading multiple buttons.· Some examples can be found in the Stamp Works examples, available freely from our website.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65


    Post Edited (Chris Savage (Parallax)) : 9/1/2009 8:19:22 PM GMT
  • cthomascthomas Posts: 17
    edited 2009-09-01 20:15
    Thanks.
  • davejamesdavejames Posts: 4,047
    edited 2009-09-02 19:55
    Mr. Savage,

    I'm building a project and need to monitor 10 switches.

    Is using 'BUTTON' not desirable in this case? I believe the PBASIC manual relates that each 'button worskspace' is a byte and so my approach would use 10 bytes of the 26 bytes of RAM available in a BS2.

    If I'm not using more than 16 additional program variables, I should be ok in terms of RAM usage?


    Yea/Nea?

    Thanks,

    DJ

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Instead of:

    "Those who can, do.· Those who can't, teach." (Shaw)
    I prefer:
    "Those who know, do.· Those who understand, teach." (Aristotle)
    ·
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-09-02 22:01
    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]I use switches in a lot of project·I have never use the button command

    I ether use IN# what ever pin·I going to use and it works very well

    IF IN0 = 1 THEN

    GOSUB YourRoutine

    ENDIF



    or·I use these routine if I want the state to ether 1 or 0· for certain amount of time before it gose to what ever routine you want it to do



    · · cntr = cntr + 1 * Chg·············· ·>> This one is used if the output = 1······· ·Chg is the pin that your switch is hook up to
    ·· IF (cntr = 10) THEN

    GOSUB Your_Routine

    ENDIF


    · cntr = cntr + 1 * (1 - Chg)········ ·>> This one is used if the output = 0
    · IF (cntr = 10) THEN

    GOSUB Your_Routine

    For me the button command dose not work for me in the project that I do

    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:23:19 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-09-03 22:21
    Davejames,

    Yes, you can use the 16 bytes if you choose and do not need them. The Stamp Works experiments I was referring to simply show another way to read the inputs at the same time, debounce and store them in a lot less space. One situation where it may be desirable to use the BUTTON command is if the duration of individual buttons changes certain program variables on the fly. For example, if you write a look for the BUTTON statement and DEBUG the work variable you will notice its value changes after some time when you hold the button down. This can be used to affect your program in a certain way. I have used it with a simple clock to make it so that holding the set button put the clock into set mode, but momentary presses were ignored. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • davejamesdavejames Posts: 4,047
    edited 2009-09-04 22:19
    @Mr. Savage,

    Understood - thank you.

    DJ

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Instead of:

    "Those who can, do.· Those who can't, teach." (Shaw)
    I prefer:
    "Those who know, do.· Those who understand, teach." (Aristotle)
    ·
Sign In or Register to comment.