Shop OBEX P1 Docs P2 Docs Learn Events
button help — Parallax Forums

button help

ArchiverArchiver Posts: 46,084
edited 2004-02-02 23:46 in General Discussion
>
> I am trying to use several buttons, each to start a different action ( sub
> routine). Basically I want a different sound from the speaker with each
> button pressed. Of course I am new to stamps with this simple question.
> Here is my code:
>
>
> '-**`1'
i/o definintions
> '
> spkr con 0
>
>
>
> '
constaants
> '
> R con 0'
> C con 33
> Cs con 35
> D con 37
> Ds CON 39
> E CON 41
> F CON 44
> Fs CON 46
> G CON 49
> Gs CON 52
> A CON 55
> As CON 58
> B CON 62
>
> N1 CON 500
> N2 CON N1/2
> N3 CON N1/3
> N4 CON N1/4
> N8 CON N1/8
>
>
> '
VARIABLES
> '
> x VAR WORD
> note1 VAR WORD
> note2 VAR WORD
> dur VAR WORD
> oct1 VAR NIB
> oct2 VAR NIB
> EE VAR BYTE
> digit VAR BYTE
> clkDly VAR WORD
> btn var byte
>
>
> again:
>
> 'debug "pin 1--", dec in1," "
> debug "pin 2--", dec in2," "
> 'debug "pin 3--", dec in3," "
> debug "pin 4--", dec in4," "
> 'debug "pin 5--", dec in5," "
> debug "pin 6---", dec in6," "
> 'debug "pin 7---", dec in7," "
> debug "pin 8---", dec in8," ", cr
>
> pause 2000
> debug cls
>
>
> 'button 1,1,255,255,btn,1,test1
> button 2,2,255,255,btn,2,test2
> 'button 3,3,255,255,btn,3,test3
> button 4,4,255,255,btn,4,test4
> 'button 5,5,255,255,btn,5,test5
> button 6,6,255,255,btn,6,test6
> 'button 7,7,255,255,btn,7,test7
> button 8,8,255,255,btn,8,test8
>
>
> pause 2000
>
>
> goto again
>
>
> test1:
> debug "switch one is on",cr
> freqout spkr,2000,350,440
>
> goto again
>
>
>
> test2:
> '
camptown song
>
> debug "switch two is on", cr
>
> 'debug "pin 1--", dec in1," "
> 'debug "pin 2--", dec in2," "
> 'debug "pin 3--", dec in3," "
> 'debug "pin 4--", dec in4," ",cr
> FOR x=0 to 13
>
> lookup X,[noparse][[/noparse]g,g,e,g,a,g,e,r,e,d,r,e,d,r],note1
> lookup X,[noparse][[/noparse]4,4,4,4,4,4,4,1,4,4,1,4,4,1],oct1
> lookup X,[noparse][[/noparse]N2,N2,N2,N2,N2,N2,N2,N2,N2,N1,N2,N2,N8],DUR
> GOSUB Play1Note
> next
> pause 1000
> '----sub
> '
> Play1Note:
> note1 = note1 << (oct1-1)
> FREQOUT spkr,dur,note1
> return
>
> goto again
>
>
>
>
>
> test3:
>
> debug "switch three is on", cr
>
> FREQOUT SPKR,2000,350,440
> goto again
>
>
>
> test4:
>
> debug "switch four is on", cr
>
> FREQOUT SPKR,5000,350,440
> goto again
>
>
>
> test5:
> debug"switch five is on",cr
>
> freqout spkr,500,500,500
> goto again
>
>
> test6:
> debug "switch six is on",cr
>
> freqout spkr, 600,600,600
> goto again
>
>
> test7:
> debug "switch seven is on", cr
> freqout spkr,700,700,700
> goto again
>
>
>
> test8:
> debug "switch eight is on",cr
> freqout spkr,800,800,800
>
>



Kelly Hoffman
Kellyh9mm@a...


[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-03-06 16:48
    The BUTTON function is best used alone and in a small loop -- and it requires
    a byte variable for each call, so you would need eight separate bytes to
    handle eight BUTTON functions. This is not the most efficient way to handle
    multiple inputs.

    Here's a small subroutine that will scan and debounce eight inputs. For
    convenience sake of the code, I would suggest you change your inputs from
    Pin1-to-Pin8 to Pin0-to-Pin7 -- you're still using eight inputs but your
    working with the natural boundaries within the Stamp; this make debounce code
    very simple.

    Here's the subroutine (assumes you inputs are active-low):

    Scan_Buttons:
    buttons = %11111111 ' assume all are pressed
    FOR idx = 1 TO 5
    buttons = buttons & ~InL ' check state, clear if not pressed
    PAUSE 10 ' debounce period (scan = 50 ms)
    NEXT
    RETURN

    Now, your program can call this routine and any button that was pressed will
    put a "1" in the corresponding bit position of "buttons." Using PBASIC 2.5
    syntax, you can then do this:

    IF buttons.LowBit(0) THEN GOSUB Test_0
    IF buttons.LowBit(1) THEN GOSUB Test_1

    and on and on. You just need to set each "Test_x" section of code as a
    subroutine (end it with RETURN).

    -- Jon Williams
    -- Applications Engineer, Parallax



    In a message dated 3/4/2003 7:43:18 PM Central Standard Time,
    Kellyh9mm@a... writes:

    > >I am trying to use several buttons, each to start a different action ( sub
    > >routine). Basically I want a different sound from the speaker with each
    > >button pressed. Of course I am new to stamps with this simple question.
    > >Here is my code:



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-02-02 03:26
    I have programmed the claw to rotate and grip with an IR remote. But instead of
    pushing the button again and again to move the claw a little each time i want to
    program it to be able to move the claw as long as my finger is on the button.
    Any examples or suggestions will appreciated.


    Do you Yahoo!?
    Yahoo! SiteBuilder - Free web site building tool. Try it!

    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-02-02 05:25
    Are you using stepper motor or servo motor and could you post your program
    so that we can help further. thanks.






    At 07:26 PM 2/1/2004, you wrote:
    >I have programmed the claw to rotate and grip with an IR remote. But
    >instead of pushing the button again and again to move the claw a little
    >each time i want to program it to be able to move the claw as long as my
    >finger is on the button. Any examples or suggestions will appreciated.
    >
    >
    >
    >Do you Yahoo!?
    >Yahoo! SiteBuilder - Free web site building tool. Try it!
    >
    >[noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the Subject and
    >Body of the message will be ignored.
    >
    >
    >Yahoo! Groups Links
    >
    >To visit your group on the web, go to:
    > http://groups.yahoo.com/group/basicstamps/
    >
    >To unsubscribe from this group, send an email to:
    > basicstamps-unsubscribe@yahoogroups.com
    >
    >Your use of Yahoo! Groups is subject to:
    > http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2004-02-02 23:46
    Im using a servo controller here is a piece of the program that moves the servo
    little by little
    servopos = 0
    servopos = servopos + 50 max 254
    if servopos > 254 then resetbutton

    Gary Denison <gdii@c...> wrote:
    Are you using stepper motor or servo motor and could you post your program
    so that we can help further. thanks.






    At 07:26 PM 2/1/2004, you wrote:
    >I have programmed the claw to rotate and grip with an IR remote. But
    >instead of pushing the button again and again to move the claw a little
    >each time i want to program it to be able to move the claw as long as my
    >finger is on the button. Any examples or suggestions will appreciated.
    >
    >
    >
    >Do you Yahoo!?
    >Yahoo! SiteBuilder - Free web site building tool. Try it!
    >
    >[noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the Subject and
    >Body of the message will be ignored.
    >
    >
    >Yahoo! Groups Links
    >
    >To visit your group on the web, go to:
    > http://groups.yahoo.com/group/basicstamps/
    >
    >To unsubscribe from this group, send an email to:
    > basicstamps-unsubscribe@yahoogroups.com
    >
    >Your use of Yahoo! Groups is subject to:
    > http://docs.yahoo.com/info/terms/


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and Body of
    the message will be ignored.


    Yahoo! Groups Links

    To visit your group on the web, go to:
    http://groups.yahoo.com/group/basicstamps/

    To unsubscribe from this group, send an email to:
    basicstamps-unsubscribe@yahoogroups.com

    Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/



    Do you Yahoo!?
    Yahoo! SiteBuilder - Free web site building tool. Try it!

    [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.