One input two outputs

edlentz

Member
Hi all
 
I want to use a button as an input to my CAI.  I already have a setup where I tell the CAI over a web page to change an output to close a relay to open one of my garage doors.  I use it to open/close either on demand.  I would like to setup a single button in the house connected to a ttl input.  I would like to press the button once and open door #1 and twice to open door #2.
 
Here is what I am using presently:

START
TSTEQ OP1[1000] 1
SET OP1 0
TSTEQ OP2[1000] 1
SET OP2 0
END

Pretty simple really
 
How woul dI do this?
 
Any help greatly appreciated!
 
You pretty much implement a flip-flop circuit in software.  You have to remember your current state then decide what to do when that button being pushed.
 
I was thnking something like sensing the first button press and waiting a preset time (2 sec), if another press during that time open door #2, if there isn't a second button press then open door #1.  I just don't know how to implement it
 
Something like this maybe:
 
 
Code:
START
    TSTEQ OP1[1000] 1
    SET OP1 0
    TSTEQ OP2[1000] 1
    SET OP2 0
    TSTEQ IP1[50] VAR1
    CALLSUB BTN_CHG
    TSTEQ IP1[1000] 0
    CALLSUB BTN_DONE
    END 

BTN_CHG:
    XOR VAR1 1 VAR1
    TSTEQ VAR1 1
    INC VAR2
    RET

BTN_DONE:
    TSTEQ VAR2 1
    SET OP1 1
    TSTEQ VAR2 2
    SET OP2 1
    SET VAR2 0
    RET
 
 
az1324 said:
Something like this maybe:
 
 
I came up with something a little different. Usual caveats apply. Not tested, etc.
 
 
Code:
START
  tsteq cts ram3 ; timeout expired?
  set op2 0 ; turn off output 2 after delay
  tsteq cts ram3 ; timeout expired?
  set op1 ram2  ; set output 1 (ram2=1 for one press, 0 for 2 presses)
  xor ip1 ram1  ; change of state of button?
  bz start
  tsteq ip1 0   ; is it now off? (just released)
  goto start
            ; if we get here we have just pressed the button.
  tstgt cts ram3 ; is this a new event?
  goto new  
  set op1 0 ; This is the second press, no need to wait. clear output 1
  set op2 1 ; and set output 2
  add cts 2 ram3 ; reset counter to end pulse
  set ram2 0 ;reset output1
  goto start
new:
  add cts 2 ram3 ; set timer
  set ram2 1 ; set op1 flag
  goto start
END
 
Thanks for the help guys!
 
Coconut
 
The first button press set the first OP to 1 and it stayed there, the second press set op2 to 1.  Both stayed on and would not go off.  
 
Ross,
 
Your code got closer,  The first button press set the first OP to 1 and it went to 0 after a couple of seconds.  2nd button presses did nothing.
 
I will look some more
 
Thanks
 
edlentz said:
Thanks for the help guys!
 
Coconut
 
The first button press set the first OP to 1 and it stayed there, the second press set op2 to 1.  Both stayed on and would not go off.  
 
Ross,
 
Your code got closer,  The first button press set the first OP to 1 and it went to 0 after a couple of seconds.  2nd button presses did nothing.
 
I will look some more
 
Thanks
 
ok, the output should have gone to 0 after 2 seconds (you can change that, or eliminate the code entirely if you wish)
As for output not going on after 2 presses.... were they both within 2 seconds of each other?
My code (should have) done nothing immediately for a single press, but after 2 seconds it should turn on OP1 for 2 seconds (then off), but a second press BEFORE that 2 seconds time and it should immediately turn on OP2.
 
Oops.  Small change:
 
az1324 said:
Something like this maybe:
 
 
Code:
START
    TSTEQ OP1[1000] 1
    SET OP1 0
    TSTEQ OP2[1000] 1
    SET OP2 0
    TSTNE IP1[50] VAR1
    CALLSUB BTN_CHG
    TSTEQ IP1[1000] 0
    CALLSUB BTN_DONE
    END 

BTN_CHG:
    XOR VAR1 1 VAR1
    TSTEQ VAR1 1
    INC VAR2
    RET

BTN_DONE:
    TSTEQ VAR2 1
    SET OP1 1
    TSTEQ VAR2 2
    SET OP2 1
    SET VAR2 0
    RET
 
 
Hey that last change got it!  Thanks!  I added [1000] to the set op1 so it would time out and it appears to work just like I want it.  I have been testing with a shorting wire LOL .  Now i need to get a button.
 
Thanks again!
 
Back
Top