Shop OBEX P1 Docs P2 Docs Learn Events
How do I say this COMMAND? — Parallax Forums

How do I say this COMMAND?

bobsmithbobsmith Posts: 36
edited 2004-09-24 00:25 in BASIC Stamp
I want my code to say if in1 = 1 for 2seconds then goto mode1

Comments

  • NewzedNewzed Posts: 2,503
    edited 2004-09-23 22:36
    Try this:

    if in1 = 1 then
    pause 2000
    if in1 = 1 then mode1

    endif





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Try the Stamp Tester

    http://hometown.aol.com/newzed/index.html
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-23 22:42
    Let me add a bit to Sid's suggestion:

    Wait_For_2Sec: 
      timer = 0
     
    Check_Input: 
      IF IN1 = 0 THEN Wait_For_2Sec
      timer = timer + 1 
      PAUSE 50 
      IF timer < 40 THEN Check_Input
    


    This version looks at the input every 50 milliseconds to make sure that the input hasn't been released then repressed during the delay period.· It forces the button to be pushed for two seconds (40 x 50 ms·= 2000 ms) before moving on.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • bobsmithbobsmith Posts: 36
    edited 2004-09-23 23:02
    Mr. Jon Williams will what the guy before said work?

    if in1 = 1 then
    pause 2000
    if in1 = 1 then mode1

    endif
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-23 23:15
    Depends on your definition of "work." What Sid's demo does is wait for the input, waits two seconds, then checks it again. Since the Stamp can't look at inputs while it's doing a PAUSE instruction, the input could be released, then reengaged and you'd never know it. Now, you said you wanted the input to be active·for 2 seconds. My version is a refinement of Sid's that, techically, could suffer the same fate, though it's far less likely that a user could release and repress the button inside a 50 millisecond window.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • bobsmithbobsmith Posts: 36
    edited 2004-09-24 00:01
    ya just to give a better view on this to you what i want to do is:

    Hold the microswitch in for 2 seconds
    when it is held in for 2 seconds it goes into mode1
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-24 00:25
    If you mean two consecutive seconds without release, then my version (or derivative of it) is what you're looking for.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.