Shop OBEX P1 Docs P2 Docs Learn Events
Button Command — Parallax Forums

Button Command

ArchiverArchiver Posts: 46,084
edited 2003-05-13 12:50 in General Discussion
You could try...

loop:
if in1 = 1 then button_is_down
goto loop

button_is_down:
pause 2000
if in1 = 1 then do_the_second_job ' if the button is still pressed, do
the second job
'put the procedure for the short button press here

do_the_second_job:
'put the procedure for the long button press here

'its a bit simple, but does the same thing.
'regds, Chris

Original Message
From: Gene Shults <gshults@o...>
To: <basicstamps@egroups.com>
Sent: Wednesday, December 13, 2000 8:58 PM
Subject: [noparse][[/noparse]basicstamps] Button Command


> I have seen before on this list, someone was wanting to
> use the input command to do two different thing.
>
> First if the switch was pushed it would do something and if it was held
> down for a long period of time it would do something else.
>
> Does anyone remember this, if so could you please help me.
>
> Thanks
> Gene
>
>
>

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-12-13 12:58
    I have seen before on this list, someone was wanting to
    use the input command to do two different thing.

    First if the switch was pushed it would do something and if it was held
    down for a long period of time it would do something else.

    Does anyone remember this, if so could you please help me.

    Thanks
    Gene
  • ArchiverArchiver Posts: 46,084
    edited 2000-12-13 19:18
    >I have seen before on this list, someone was wanting to
    >use the input command to do two different thing.
    >
    >First if the switch was pushed it would do something and if it was held
    >down for a long period of time it would do something else.
    >
    >Does anyone remember this, if so could you please help me.
    >
    >Thanks
    >Gene


    Stamps-in-class has tutorial
    http://www.emesys.com/EarthM/em2.pdf
    covers pushbutton responding to single click, long click, and double click.

    I don't usually use the button command, because specific results can
    be achieved with program loops. More info about the internal workings
    of BUTTON at:
    http://www.emesys.com/BS2buttn.htm

    -- Tracy Allen
    Electronically Monitored Ecosystems
    Berkeley CA U.S.A.
  • ArchiverArchiver Posts: 46,084
    edited 2000-12-13 21:07
    unsuscribe



    Original Message
    From: "Gene Shults" <gshults@o...>
    To: <basicstamps@egroups.com>
    Sent: Wednesday, December 13, 2000 1:58 PM
    Subject: [noparse][[/noparse]basicstamps] Button Command


    > I have seen before on this list, someone was wanting to
    > use the input command to do two different thing.
    >
    > First if the switch was pushed it would do something and if it was held
    > down for a long period of time it would do something else.
    >
    > Does anyone remember this, if so could you please help me.
    >
    > Thanks
    > Gene
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2000-12-13 21:07
    stop




    Original Message
    From: "Gene Shults" <gshults@o...>
    To: <basicstamps@egroups.com>
    Sent: Wednesday, December 13, 2000 1:58 PM
    Subject: [noparse][[/noparse]basicstamps] Button Command


    > I have seen before on this list, someone was wanting to
    > use the input command to do two different thing.
    >
    > First if the switch was pushed it would do something and if it was held
    > down for a long period of time it would do something else.
    >
    > Does anyone remember this, if so could you please help me.
    >
    > Thanks
    > Gene
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2000-12-13 21:07
    stop



    Original Message
    From: "Gene Shults" <gshults@o...>
    To: <basicstamps@egroups.com>
    Sent: Wednesday, December 13, 2000 1:58 PM
    Subject: [noparse][[/noparse]basicstamps] Button Command


    > I have seen before on this list, someone was wanting to
    > use the input command to do two different thing.
    >
    > First if the switch was pushed it would do something and if it was held
    > down for a long period of time it would do something else.
    >
    > Does anyone remember this, if so could you please help me.
    >
    > Thanks
    > Gene
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2000-12-13 21:08
    unsuscribe





    Original Message
    From: "Gene Shults" <gshults@o...>
    To: <basicstamps@egroups.com>
    Sent: Wednesday, December 13, 2000 1:58 PM
    Subject: [noparse][[/noparse]basicstamps] Button Command


    > I have seen before on this list, someone was wanting to
    > use the input command to do two different thing.
    >
    > First if the switch was pushed it would do something and if it was held
    > down for a long period of time it would do something else.
    >
    > Does anyone remember this, if so could you please help me.
    >
    > Thanks
    > Gene
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-10-16 08:11
    Hello Stampers,

    When using the button command it is necessary to define a byte variable
    cleared to 0 at start time.

    The manual says:

    BUTTON Pin, DownState, Delay, Rate, Workspace, TargetState, Address

    Where workspace is the byte variable.

    When using several button commands in a loop for scanning 11 push buttons
    like:

    code


    workspace var byte 'used by button command
    workspace=0

    scan_buttons:

    button 1,0,255,0,workspace,1,button_1_pressed
    button 2,0,255,0,workspace,1,button_2_pressed
    button 3,0,255,0,workspace,1,button_3_pressed
    .......
    .......

    button 10,0,255,0,workspace,1,button_10_pressed
    button 11,0,255,0,workspace,1,button_11_pressed

    goto scan_buttons

    end
    code

    Can I use the same byte variable "workspace" for every button command or do
    I have to define a different byte variable for each button command.

    like

    workspace1 var byte 'used by button1
    workspace2 var byte 'used by button2
    workspace3 var byte 'used by button3
    etc.

    I hope not because this "eats" variable space ;-(


    BTW has anyone ever wrote a program for controlling an H-bridge powered DC
    motor activated by to pushbuttons "left" & "right" including the left and
    right overrun switches?


    Thanks in advance

    Michel De Meester
    Belgium


    Met vriendelijke groetjes,

    > ************************************************
    > Michel De Meester
    > Biotechnisch Onderhoud
    > Universitair Ziekenhuis Antwerpen
    > Wilrijkstraat 10
    > 2650 Edegem - B
    > tel: ++32 (0)3 821 36 47
    > e-mail: michel.de.meester@u...
    >
    > *************************************************
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-10-16 13:22
    No, you need a separate variable for each button command.

    Regards,

    Al Williams
    AWC
    * Control 8 servos at once
    http://www.al-williams.com/awce/pak8.htm

    Original Message
    From: De Meester, Michel [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=lyRvyZxe5rwFj5J474_1mo8C3eOuMhvR1JZebFDRL7h98koQFgcULd-0Gr7qsrjGQ4eHKVBLEPfEdZ614gJMfwbcHUpE]Michel.De.Meester@u...[/url
    Sent: Tuesday, October 16, 2001 2:12 AM
    To: 'basicstamps@yahoogroups.com'
    Subject: [noparse][[/noparse]basicstamps] Button Command


    Hello Stampers,

    When using the button command it is necessary to define a byte variable
    cleared to 0 at start time.

    The manual says:

    BUTTON Pin, DownState, Delay, Rate, Workspace, TargetState, Address

    Where workspace is the byte variable.

    When using several button commands in a loop for scanning 11 push buttons
    like:

    code


    workspace var byte 'used by button command
    workspace=0

    scan_buttons:

    button 1,0,255,0,workspace,1,button_1_pressed
    button 2,0,255,0,workspace,1,button_2_pressed
    button 3,0,255,0,workspace,1,button_3_pressed
    .......
    .......

    button 10,0,255,0,workspace,1,button_10_pressed
    button 11,0,255,0,workspace,1,button_11_pressed

    goto scan_buttons

    end
    code

    Can I use the same byte variable "workspace" for every button command or do
    I have to define a different byte variable for each button command.

    like

    workspace1 var byte 'used by button1
    workspace2 var byte 'used by button2
    workspace3 var byte 'used by button3
    etc.

    I hope not because this "eats" variable space ;-(


    BTW has anyone ever wrote a program for controlling an H-bridge powered DC
    motor activated by to pushbuttons "left" & "right" including the left and
    right overrun switches?


    Thanks in advance

    Michel De Meester
    Belgium


    Met vriendelijke groetjes,

    > ************************************************
    > Michel De Meester
    > Biotechnisch Onderhoud
    > Universitair Ziekenhuis Antwerpen
    > Wilrijkstraat 10
    > 2650 Edegem - B
    > tel: ++32 (0)3 821 36 47
    > e-mail: michel.de.meester@u...
    >
    > *************************************************
    >
    >

    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.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-12-21 03:40
    Why might a button command work properly with a 'debug' in a target loop,
    but not when the 'debug' is 'rem'd out?
    Any clues?
    CL
  • ArchiverArchiver Posts: 46,084
    edited 2001-12-21 04:43
    This sounds like one of those Stamp issues. I think the FREQOUT command
    behaves the same way. Just always put the "Hello World" line in there at
    the top of the program and everything will work out.


    Original Message


    > Why might a button command work properly with a 'debug' in a target loop,
    > but not when the 'debug' is 'rem'd out?
    > Any clues?
  • ArchiverArchiver Posts: 46,084
    edited 2001-12-21 12:46
    Hi,

    My guess is you are experiencing debounce effects.
    With the debug in place your switch gets enough time
    to settle. Without debug the time is too short.
    Try increasing the debounce delay in the button command.
    To effectively suppress debounce effects place a small
    cap between your stamp pin and gnd (assuming you have a pullup resistor)

    Regards peter



    Oorspronkelijk bericht
    Van: Chris Loiacono [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=vDE67RUe-AOUaGy921zTMCJM0qvZXiPYCP4OQhq7CusTOmjTTvRxKr9BPosMXvSxEpA1bWv2AgzQntygRw]chris@m...[/urlNamens Chris Loiacono
    (E-mail)
    Verzonden: donderdag 20 december 2001 19:41
    Aan: Basicstamps Group (E-mail)
    Onderwerp: [noparse][[/noparse]basicstamps] Button command

    Why might a button command work properly with a 'debug' in a target loop,
    but not when the 'debug' is 'rem'd out?
    Any clues?
    CL


    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.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-12-21 14:25
    >
    Original Message
    > From: Chris Loiacono [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=3heUClSXFrls0G0k2tEWT_hJTJroAuvEAquD5wLsOvRNdeKPgvYPv9wTxSv36doli_aUTlLKPvGYSDhUmw]chris@m...[/url
    > Sent: Friday, December 21, 2001 8:30 AM
    > To: 'basicstamps@yahoogroups.com'
    > Subject: RE: [noparse][[/noparse]basicstamps] Button command
    >
    >
    > Thanks. That's what I was afraid of. *** Device
    > Limitations***, or unexplainable phenomena, only the effects
    > of which are visible.
    > >
    > > This sounds like one of those Stamp issues. I think the
    > > FREQOUT command
    > > behaves the same way. Just always put the "Hello World" line
    > > in there at
    > > the top of the program and everything will work out.
    > >
    > >
    > >
    Original Message
    > >
    > >
    > > > Why might a button command work properly with a 'debug' in
    > > a target loop,
    > > > but not when the 'debug' is 'rem'd out?
    > > > Any clues?
    > >
    > >
    > >
    > >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-12-21 14:25
    >
    Original Message
    > From: Chris Loiacono [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=CFucUdPfGJxYojS69br5x3-9XaYo8hV3gFUv1IQk9YaW5C7-GTf4Kj8k3hYiA-Zzy_0DSxQePj4Zx9aH]chris@m...[/url
    > Sent: Friday, December 21, 2001 8:35 AM
    > To: 'basicstamps@yahoogroups.com'
    > Subject: RE: [noparse][[/noparse]basicstamps] Button command
    >
    >
    > Thanks Peter,
    > Been there, done that (though it's not often the case).
    > I've tried longest delay, "decoupling" the signal, and yes -
    > it is pulled up.
    > Nada, nada. (Or is it yada, yada - OK to poke fun at myself, no?)
    > I may just leave the extra statement in the program. I sure
    > would like to understand why this is happening....Jon, are
    > you listening?
    > Chris
    >
    > >
    Original Message
    > > From: peter verkaik [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=kQiZPwhoK1A_u63oQvsCq5ZHyx2Htvvph6sFZRKdJUwK_jFttjO_a4HPc6Ashhy5uCDv0djDVfaBhSUcBY7wvtw]peterverkaik@b...[/url
    > > Sent: Friday, December 21, 2001 7:46 AM
    > > To: basicstamps@yahoogroups.com
    > > Subject: RE: [noparse][[/noparse]basicstamps] Button command
    > >
    > >
    > > Hi,
    > >
    > > My guess is you are experiencing debounce effects.
    > > With the debug in place your switch gets enough time
    > > to settle. Without debug the time is too short.
    > > Try increasing the debounce delay in the button command.
    > > To effectively suppress debounce effects place a small
    > > cap between your stamp pin and gnd (assuming you have a
    > > pullup resistor)
    > >
    > > Regards peter
    > >
    > >
    > >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-12-22 00:11
    Hi,

    I don't use button that often but never had that problem.
    If you replace the debug statement with pause 10
    does the button command work properly then?
    Just to rule out debouncing.

    Regards peter


    Oorspronkelijk bericht
    Van: Chris Loiacono [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=9uGOqOgdr3l5AY0IYVa7AVOhKk5yAxdycjHEZ5y4chaiB5xHF3nxhfk4EFznmrOHxlGJmqnL2H90vIA]chris@m...[/urlNamens Chris Loiacono
    (E-mail)
    Verzonden: vrijdag 21 december 2001 6:25
    Aan: Basicstamps Group (E-mail)
    Onderwerp: FW: [noparse][[/noparse]basicstamps] Button command


    >
    Original Message
    > From: Chris Loiacono [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=9uGOqOgdr3l5AY0IYVa7AVOhKk5yAxdycjHEZ5y4chaiB5xHF3nxhfk4EFznmrOHxlGJmqnL2H90vIA]chris@m...[/url
    > Sent: Friday, December 21, 2001 8:35 AM
    > To: 'basicstamps@yahoogroups.com'
    > Subject: RE: [noparse][[/noparse]basicstamps] Button command
    >
    >
    > Thanks Peter,
    > Been there, done that (though it's not often the case).
    > I've tried longest delay, "decoupling" the signal, and yes -
    > it is pulled up.
    > Nada, nada. (Or is it yada, yada - OK to poke fun at myself, no?)
    > I may just leave the extra statement in the program. I sure
    > would like to understand why this is happening....Jon, are
    > you listening?
    > Chris
    >
    > >
    Original Message
    > > From: peter verkaik [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=hFSIVccb9tj6Ptovdqh4jf8T8VeKg9ny5WtveBOnHGmw_fy8FnZ_tekf3gycSszasK7iWcyJB3zwAL0pqo6c5Ms]peterverkaik@b...[/url
    > > Sent: Friday, December 21, 2001 7:46 AM
    > > To: basicstamps@yahoogroups.com
    > > Subject: RE: [noparse][[/noparse]basicstamps] Button command
    > >
    > >
    > > Hi,
    > >
    > > My guess is you are experiencing debounce effects.
    > > With the debug in place your switch gets enough time
    > > to settle. Without debug the time is too short.
    > > Try increasing the debounce delay in the button command.
    > > To effectively suppress debounce effects place a small
    > > cap between your stamp pin and gnd (assuming you have a
    > > pullup resistor)
    > >
    > > Regards peter
    > >
    > >
    > >
    >

    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.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-12-22 06:49
    > > Thanks. That's what I was afraid of. *** Device
    > > Limitations***, or unexplainable phenomena, only the effects
    > > of which are visible.
    >Why might a button command work properly with a 'debug' in a target loop,
    >but not when the 'debug' is 'rem'd out?
    >Any clues?
    >CL

    Hi Chris,

    What is the shortest program you can come up with that illustrates
    this problem? I can't believe it is _that_ mysterious!!!

    -- Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2001-12-23 05:11
    Do you happen to be running W2K on that machine? I have the same
    problem and it might be a W2K problem and not a BS problem.

    hankster

    --- In basicstamps@y..., "Chris Loiacono (E-mail)" <chris01@t...>
    wrote:
    > Why might a button command work properly with a 'debug' in a
    target loop,
    > but not when the 'debug' is 'rem'd out?
    > Any clues?
    > CL
  • ArchiverArchiver Posts: 46,084
    edited 2002-04-19 14:10
    Hello Stamper guys (and girls)

    I have to check the state of four push buttons for starting and stopping dc
    motors (btw the problem with th H-bridge is solved I use a L298 now)

    wath do I want exactly to do:

    when the button "left" is pressed, the motor start turnig lef (until it
    reaches an overrunswitch)
    when the button "left" is pushed again notting will happen
    when the button "right" is pressed while the motor runs left, the motor has
    to stop
    when the button "right" is pressed again, the motor start turnig right
    (until it reaches an overrunswitch)

    the motor can then be stopped by pressing the "left" switch and restarted
    left (or right) and so on


    What is the problem:

    When I push the "left" button the motor start turning left
    When I then push the "right" button to stop the motor, the motor stops, but
    starts immediatly turning right because the program loop in wich the inputs
    are scanned is already executed again and still sees the "right" button
    pressed (he is of coarse still pressed, the stamp is just to fast ;-)

    Isn't here a way to scan for the high to low change of an input, so holding
    down th input will only trigger once the subroutine jump.

    Thx in advance





    the program listing kan be found at
    http://users.pandora.be/jff/tankmotorsturing/tankmotorsturing.html
    Met vriendelijke groetjes,

    > ************************************************
    > Michel De Meester
    > Biotechnisch Onderhoud
    > Universitair Ziekenhuis Antwerpen
    > Wilrijkstraat 10
    > 2650 Edegem - B
    > tel: ++32 (0)3 821 36 47
    > e-mail: michel.de.meester@u...
    >
    > *************************************************
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-04-19 18:16
    >when the button "left" is pressed, the motor start turnig lef (until it
    >reaches an overrunswitch)
    >when the button "left" is pushed again notting will happen
    >when the button "right" is pressed while the motor runs left, the motor has
    >to stop
    >when the button "right" is pressed again, the motor start turnig right
    >(until it reaches an overrunswitch)
    >
    >the motor can then be stopped by pressing the "left" switch and restarted
    >left (or right) and so on


    Here is a way to do it, as a state machine. The keyDetect routine
    uses the xor operator (^ on the stamp) to flag the _change_ 1 --> 0
    in the input state of the switches. There are state variables for
    the old and new state of the 4 switches, and also a state variable
    for the key change. Also a state variable for the motors.


    motor var nib ' two bits for each motor.
    ' xx00=stop, xx01=right, xx10=left
    ' 00xx=stop, 01xx=right, 10xx=left
    keys var nib ' new state of switches
    key0 var nib ' old state of switches
    keyx var nib ' change in state of switches

    key0 = inA ' state at start
    keyDetect:
    keys=inA
    keyx=keys^key0&key0 ' detects change 0-->1
    key0=keys
    if keyx then processKey ' do only if key press
    goto loop

    processKey:
    motor=motor|keyx ' set the direction bit
    if motor&%0011<>%0011 then p1 ' xx11 --> xx00
    motor=motor&%1100
    p1:
    if motor&%1100<>%1100 then p2 ' 11xx --> 00xx
    motor=motor&%0011
    p2:
    outA=motor ' set motor direction
    goto keyDetect ' look for key action


    Here is an alternative for the processKey routine, that uses static
    logic operators instead of if-then to get the motor state. The
    variable keys is reused as a scratch variable. (You don't really
    need the variable motor in any of this--it too is really a scratch
    variable.)

    process:
    motor=motor|keyx
    keys=motor&%1010>>1&(motor&%0101)
    keys=keys<<1|keys
    motor=motor&~keys
    outA=motor
    goto loop

    I hope that helps. I have more write-up on state machines at
    <http://www.emesystems.com/BS2fsm.htm>

    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com
  • ArchiverArchiver Posts: 46,084
    edited 2002-04-20 02:39
    Hi Michel

    In looking at my earlier post on the state logic, I wanted to clean
    it up a bit.

    ' 4 switches on 4 bits of inA, active low
    ' 2 motors on 4 bits of outB, bits in pairs
    ' motor 1: xx01 right, xx10 left, xx00 stop, xx11 not allowed
    ' motor 2: 01xx right, 10xx left, 00xx stop, 11xx not allowed

    key0 var nib ' store prior state of keys
    keys var nib ' current state of keys
    keyx var nib ' change in state of keys
    X var keyx ' temporary variable, =keyx
    Y var keys ' ditto, =keys

    dirB=%1111 ' all outputs for motors
    key0 = inA ' startup state of keys

    keyDetect:
    keys=inA ' get current key state
    keyx=keys^key0&key0 ' detects change 1-->0
    ' change --> bit=1 in keyx
    key0=keys ' renew prior state
    if keyx then processKey ' do only if key press
    goto keyDetect


    processKey: ' enter with keyx<>0
    X= outB | keyx ' tentative state of motors
    Y= (X & %1010 >> 1) & (X & %0101) ' detects %11 pair(s)
    Y= Y << 1 | Y ' creates %11 mask
    outB= X & ~Y ' final state of motors
    goto keyDetect

    For example, if the current output happens to be outB=1001, then
    motor 2 is turning left and motor 1 is turning right. All keys are
    up, %1111. If the user now presses the button in position %1101, the
    keyDetect routine catches the change and jumps to processKey with
    keyx=%0010. When keyx is ORed with the current motor state, outB,
    that makes the tentative motor state X=%1011. The next two lines
    starting with "Y=" detect the 11 pair in the two low bits and create
    a mask %0011. The final expression then ANDs the tentative state
    with NOT ("~") the mask, to give the new motor state, %1000. Motor 1
    stopped. The user has to release the motor 1 "left" button and then
    press it again to generate another keyx event. (That was your
    question.) This time through processKey, the tentative motor state
    is 1010. The cross terms are all zero, so the NOT~mask is ~Y=%1111,
    and the final motor state is %1010, both motors turning left.

    The nice thing about using math (instead of if-then) to detect the
    %11 condition is that it takes exactly the number of lines of code to
    do 8 switches and 4 motors, simply by using bytes instead of nibs.

    -- best regards
    Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com/BS2fsm.htm <--- more state machines!
    mailto:tracy@e...


    >when the button "left" is pressed, the motor start turnig lef (until
    >it>reaches an overrunswitch)
    >when the button "left" is pushed again notting will happen
    >when the button "right" is pressed while the motor runs left, the motor has
    >to stop
    >when the button "right" is pressed again, the motor start turnig right
    >(until it reaches an overrunswitch)
    >
    >the motor can then be stopped by pressing the "left" switch and restarted
    >left (or right) and so on
    >What is the problem:
    >
    >When I push the "left" button the motor start turning left
    >When I then push the "right" button to stop the motor, the motor stops, but
    >starts immediatly turning right because the program loop in wich the inputs
    >are scanned is already executed again and still sees the "right" button
    >pressed (he is of coarse still pressed, the stamp is just to fast ;-)
    >
    >Isn't here a way to scan for the high to low change of an input, so holding
    >down th input will only trigger once the subroutine jump.
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-13 09:14
    This URL goes into more detail on the inner workings of BUTTON:

    http://www.emesystems.com/BS2fsm.htm#BUTTON

    -- Tracy


    >I'm a newbie and need a bit of help...
    >
    >Perhaps someone could explain the BUTTON command a bit
    >more in depth for me. The manual just seems to
    >confuse me. For instance, downstate vs.
    >targetstate...wha??
    >
    >I'm am trying to set up something with a number of
    >momentary switches, and depending on which one is
    >depressed at any one moment, send specific serial info
    >to a PC. It would be nice to be able to detect
    >multiple closed switches, but for now I'm just going
    >for one at a time.
    >
    >My switches are set up in an active-low state. I keep
    >getting repeat while the button is depressed or
    >infinite repeat while open. The sample code in the
    >manual doesn't help much... any suggestions?
    >
    >Thanks,
    >--Andrew
    >
    >__________________________________________________
    >Do you Yahoo!?
    >Yahoo! Shopping - Send Flowers for Valentine's Day
    >http://shopping.yahoo.com
    >
    >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.
    >
    >
    >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-13 16:51
    Here is what I do for switch debounce (it isn't the BEST way, but it works
    for me) -

    Suppose we have a pin that is HIGH until the switch is pressed.

    Wait in a loop until the pin goes LOW.
    PAUSE for a few milliseconds to let contact bounce subside (I tend to use
    10 to 50 ms)
    If the pin is no longer low, then this was just bounce or noise - ignore it
    - go back to waiting until pin goes low
    If pin is still low, then loop until it goes high again - when it does, the
    user has released the button and you can do what you want.

    A better way (but hard to do on the stamp - I do this with a PIC) is to
    actually measure the time that the button is down and if it is greater
    than the bounce time (e.g. 10 ms), consider the button to be pressed. This
    is easy on a PIC where you can actually measure times. If you have a good
    idea of the instruction timings on the stamp, you can measure time by the
    number of passes though a loop.

    Larry



    At 07:39 AM 2/13/2003 -0800, you wrote:
    >Thanks for the article, Tracy.
    >
    >As a conclusion, am I right to assume that more than
    >one switch using the BUTTON command is too much
    >trouble than it's worth? Is a state machine always
    >easier?
    >
    >Thanks again,
    > >Andrew
    >
    >__________________________________________________
    >Do you Yahoo!?
    >Yahoo! Shopping - Send Flowers for Valentine's Day
    >http://shopping.yahoo.com
    >
    >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.
    >
    >
    >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

    Larry Bradley
    Orleans (Ottawa), Ontario, CANADA
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-13 17:29
    Hi Andrew,

    I'd say, the BUTTON command is overkill unless you need the
    auto-repeat capability. Each BUTTON needs one byte for workspace,
    whereas for simple debounce or state transition detection all that is
    necessary is one bit. That really adds up if you have many buttons.

    -- Tracy



    >Thanks for the article, Tracy.
    >
    >As a conclusion, am I right to assume that more than
    >one switch using the BUTTON command is too much
    >trouble than it's worth? Is a state machine always
    >easier?
    >
    >Thanks again,
    > >Andrew
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-13 20:05
    Hi Andrew,

    You need to store both the current state of InA and the previous
    state, There is one bit in each nib for each button, for its present
    and previous state, 0=down and 1=up. When a bit changes from 0 to 1,
    then you do your SEROUT for the corresponding button(s). You have to
    have both the previous and present state in order to detect changes.

    Example (taken from my URL on state machines)

    '($PBASIC 2.5}
    do
    x1 = inA ' get state of all 4 input pushbuttons or sensors
    xx=x1^x0&x1 ' detect changes, bit =1 when button is released
    x0=x1 ' update old state of all 3 buttons
    if xx.bit1=1 then debug "second button",cr
    loop ' over and over

    The third nib variable xx is for the transitions. The computation
    uses the boolean AND and XOR operators. ("&" and "^" in Stampese)

    -- regards
    Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
    mailto:tracy@e...


    >Ok...I see the light at the end of the tunnel.
    >Thanks for all the input from everyone. I've got my
    >switches reading accurately and reliably.
    >
    >One final quesiton [noparse];)[/noparse] I am trying to send a character
    >via SEROUT depending on which switches are triggered
    >("0", "1", "2", etc.).
    >
    >If I were to test InA and receive back %0010 (telling
    >me that pin1 had just been pressed & released), how
    >could I translate that into 'if bitX = 1 then serout
    >"X"'...?
    >
    >Thanks,
    >--andrew
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-12 23:38
    I used the following commands to check the state of a mechanical
    switch. I connected IO pin 8 to +5 and the switch, and I connected
    the ground to the other side of the switch. When I press the switch
    it debugs "notpressed" just as it should. The problem is, it works on
    any IO pin, not just 8. want to use button to monitor many switches
    not just one and it wont work it this happens. Any help is appreciate.

    '{$STAMP BS2}
    Bttn var byte
    Bttn=0
    Loop:
    button 8,0,255,250,Bttn,0,NotPressed
    debug "button pressed!"
    NotPressed:goto Loop
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-13 12:50
    make sure you connect the pin (8) in this case and any other ones you wish
    to use through a seperate resistor ( 4.7K) is fine to +5volts and the other
    end to the stamp pin. Connect the switch between the stamp pin and ground.
    When you press the button, the voltage will be dropped through the resistor
    and the stamp will see a low and detect it. I suspect you are just pulling
    down the 5 volt supply causing erroneous readings. If you wish to look at
    several switches, wire each like this and instead of goto loop, call the
    next button routine and on the last, goto loop.

    jim

    http://geocities.com/jimforkin2003/

    Original Message
    From: mstroboto2003 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=u8hxbKt3pCLroH-3kjczDJel4f5XKxKqPu9IFyFa2HxsDlJui_Lu4zfAuACR1E9ImiTMGAK2ehHIOCI1]monkeymack@a...[/url
    Sent: Monday, May 12, 2003 6:39 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] button command


    I used the following commands to check the state of a mechanical
    switch. I connected IO pin 8 to +5 and the switch, and I connected
    the ground to the other side of the switch. When I press the switch
    it debugs "notpressed" just as it should. The problem is, it works on
    any IO pin, not just 8. want to use button to monitor many switches
    not just one and it wont work it this happens. Any help is appreciate.

    '{$STAMP BS2}
    Bttn var byte
    Bttn=0
    Loop:
    button 8,0,255,250,Bttn,0,NotPressed
    debug "button pressed!"
    NotPressed:goto Loop


    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.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Sign In or Register to comment.