Switching immediately a input to a output
Archiver
Posts: 46,084
Hi,
I want to make a little switching program with 3 inputs (switches) en 3
outputs (led’s). When input 1 is high, then lamp 1 is high, When input 2 is
high, then lamp 2 is high, and the same for switch and
Lamp 3. The problem is that the program must be fast and when for example
input 1 and 2 are high the output’s 1 and 2 must be high. The stamp must
immediately react when an input is high and must make the output high. It is
the meaning that the stamp always reacts on the inputs and when a particular
input is high, the corresponding output will be high. I designed already a
little program but when a switch is already high and I push another switch
to on, the stamp will not react to the second input because switch one stay’
s in his loop.
Could anybody give me a possibility to improve this program? I use the
BS2P-24.
Kindly regards
Tim (Belgium)
'++++++++++++++++++++++++++++++++++
x con 100
'++++++++++++++++++++++++++++++++++
Basis:
gosub therm1
gosub therm2
gosub therm3
goto Basis
therm1:
if in1=0 then therm1aan
return
therm2:
if in2=0 then therm2aan
return
therm3:
if in3=0 then therm3aan
return
therm1aan:
high 4
pause x
low 4
goto therm1
therm2aan:
high 5
pause x
low 5
goto therm2
therm3aan:
high 6
pause x
low 6
goto therm3
[noparse][[/noparse]Non-text portions of this message have been removed]
I want to make a little switching program with 3 inputs (switches) en 3
outputs (led’s). When input 1 is high, then lamp 1 is high, When input 2 is
high, then lamp 2 is high, and the same for switch and
Lamp 3. The problem is that the program must be fast and when for example
input 1 and 2 are high the output’s 1 and 2 must be high. The stamp must
immediately react when an input is high and must make the output high. It is
the meaning that the stamp always reacts on the inputs and when a particular
input is high, the corresponding output will be high. I designed already a
little program but when a switch is already high and I push another switch
to on, the stamp will not react to the second input because switch one stay’
s in his loop.
Could anybody give me a possibility to improve this program? I use the
BS2P-24.
Kindly regards
Tim (Belgium)
'++++++++++++++++++++++++++++++++++
x con 100
'++++++++++++++++++++++++++++++++++
Basis:
gosub therm1
gosub therm2
gosub therm3
goto Basis
therm1:
if in1=0 then therm1aan
return
therm2:
if in2=0 then therm2aan
return
therm3:
if in3=0 then therm3aan
return
therm1aan:
high 4
pause x
low 4
goto therm1
therm2aan:
high 5
pause x
low 5
goto therm2
therm3aan:
high 6
pause x
low 6
goto therm3
[noparse][[/noparse]Non-text portions of this message have been removed]
Comments
Your original program will "retrigger" if it brings the LED on, pauses,
and then the switch is still active. This may or may not be what you
want, but I've preserved that behavior.
How about this:
S1count var byte
S2count var byte
S3 count var byte
S1 var in1
S2 var in2
S3 var in3
ACTIVE con 0 ' switch active state
DELAY con 30 ' experimentally found value for delay
LED1 con 4
LED2 con 5
LED3 con 6
Main:
S1count=0
S2count=0
S3count=0
LOW LED1
LOW LED2
LOW LED3
Loop:
' check for LEDs off
Ckoff:
If S1count=0 then Ck1on
S1count=S1count-1
If S1count<>0 then Ck2off
LOW LED1
Ck2off:
If S2count=0 then Ck2on
S2count=S2count-1
If S2count<>0 then Ck3off
LOW LED2
Ck3off:
If S3count=0 then Ck3on
S3count=S3count-1
If S3count<>0 then Loop
LOW LED3
Goto Loop
Ck1on:
If S1<>ACTIVE then Ck2off
' switch 1 active
HIGH LED1
S1count=DELAY
Goto Ck2off
Ck2on:
If S2<>ACTIVE then Ck3off
HIGH LED2
S2count=DELAY
Goto Ck3off
Ck3on:
If S3<>ACTIVE then Loop
HIGH LED3
S3count=DELAY
Goto Loop
You could change the behavior if you wanted to. For example, if you put
Ck1on/Ck2on/Ck3on first (and changed the gotos appropriately) the
switches would keep the LEDs on until you released the switches. Then
the delay would kick in. There are many possibilities.
If you just wanted the LEDs to track the switch state, you could do this
much simpler. For example:
' Switches on 0 1 and 2 (pin 3 unused); LEDs on 4 5 6 (7 unused)
LOW 4
LOW 5
LOW 6 ' could use DIR register here instead
Loop:
OUTB=INA
Goto Loop
This assumes that the switches go active the same way the LEDs do. If
not, try something like:
OUTB=~INA
Hope that gives you some ideas.
Al Williams
AWC
* Control 8 servos at once
http://www.al-williams.com/awce/pak8.htm
>
Original Message
> From: TLD-NV [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=MwDvaK7fBshu0IHGj9cOt4lu_GR8vO4xQ7tNcjoLgRcGZrwGCGZmugaJcNyVIC6bmldEueuILDJeIBMZmQtrEYyWrm0]peter.christiaen@s...[/url
> Sent: Wednesday, November 13, 2002 6:30 AM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] Switching immediately a input to a output
>
>
> Hi,
> I want to make a little switching program with 3 inputs
> (switches) en 3 outputs (led's). When input 1 is high, then
> lamp 1 is high, When input 2 is high, then lamp 2 is high,
> and the same for switch and Lamp 3. The problem is that the
> program must be fast and when for example input 1 and 2 are
> high the output's 1 and 2 must be high. The stamp must
> immediately react when an input is high and must make the
> output high. It is the meaning that the stamp always reacts
> on the inputs and when a particular input is high, the
> corresponding output will be high. I designed already a
> little program but when a switch is already high and I push
> another switch to on, the stamp will not react to the second
> input because switch one stay' s in his loop. Could anybody
> give me a possibility to improve this program? I use the BS2P-24.
>
> Kindly regards
>
> Tim (Belgium)
> '++++++++++++++++++++++++++++++++++
> x con 100
> '++++++++++++++++++++++++++++++++++
>
> Basis:
> gosub therm1
> gosub therm2
> gosub therm3
> goto Basis
>
> therm1:
> if in1=0 then therm1aan
> return
>
> therm2:
> if in2=0 then therm2aan
> return
>
> therm3:
> if in3=0 then therm3aan
> return
>
> therm1aan:
> high 4
> pause x
> low 4
> goto therm1
>
> therm2aan:
> high 5
> pause x
> low 5
> goto therm2
>
> therm3aan:
> high 6
> pause x
> low 6
> goto therm3
>
>
>
>
>
> [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.
>
>
> Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
Tim