Tutorials:Controlling devices with multiple switches: Difference between revisions

Building pieces of another world.
Jump to navigation Jump to search
gravatar The Watcher [userbureaucratsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
(Created page with "Consider the situation where you have two doors into a room, each with a light switch next to it, or a switch at the top and bottom of a flight of stairs. Either switch needs to ...")
 
gravatar The Watcher [userbureaucratsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
No edit summary
Line 2: Line 2:


[[Image:Tutorial-MultiSwitch.png|500px|center|thumbnail]]
[[Image:Tutorial-MultiSwitch.png|500px|center|thumbnail]]


(Note: this is actually an implementation of an exclusive-OR gate..)
(As a side note, this is actually an implementation of an exclusive-OR gate..)


The "Any" object is a RequireAnyTrap (an OR gate), the two "all" objects are RequireAllTraps (AND gates) and Inv is an Inverter. S1 and S2 are the input switches, O is the output (which may be one or more objects). To set this up in Dromed:
The "Any" object is a RequireAnyTrap (an OR gate), the two "All" objects are RequireAllTraps (AND gates) and Inv is an Inverter. S1 and S2 are the input switches, O is the output (which may be one or more objects). To set this up in Dromed:
Place your two switches, call them S1 and S2.
 
Add the objects you want to control - lights, doors, whatever.
* Place your two switches, call them S1 and S2.
Add one RequireAnyTrap fnord and rename it Any.
* Add the objects you want to control - lights, doors, whatever.
Add two RequireAllTrap fnords and call them All1 and All2.
* Add one RequireAnyTrap fnord and rename it Any.
Add one Inverter fnord, call it Inv.
* Add two RequireAllTrap fnords and call them All1 and All2.
Add a ControlDevice link from S1 to Any.
* Add one Inverter fnord, call it Inv.
Add a ControlDevice link from S1 to All1.
* Add a ControlDevice link from S1 to Any.
Add a ControlDevice link from S2 to Any.
* Add a ControlDevice link from S1 to All1.
Add a ControlDevice link from S2 to All1.
* Add a ControlDevice link from S2 to Any.
Add a ControlDevice link from Any to All2 (line a on the diagram).
* Add a ControlDevice link from S2 to All1.
Add a ControlDevice link from All1 to Inv (line b on the diagram).
* Add a ControlDevice link from Any to All2 (line a on the diagram).
Add a ControlDevice link from Inv to All2 (line c on the diagram).
* Add a ControlDevice link from All1 to Inv (line b on the diagram).
Add ControlDevice links from All2 to all the controlled objects.
* Add a ControlDevice link from Inv to All2 (line c on the diagram).
* Add ControlDevice links from All2 to all the controlled objects.


To see how this works, have a look at this truth table:
To see how this works, have a look at this truth table:
<table class="zebra">
<table class="zebra">
<tr>
<tr>
Line 38: Line 37:
<tr><td>4:</td><td>On</td> <td>On</td> <td>On</td> <td>On</td> <td>Off</td><td>Off</td></tr>
<tr><td>4:</td><td>On</td> <td>On</td> <td>On</td> <td>On</td> <td>Off</td><td>Off</td></tr>
</table>
</table>
For example, say that initially both switches are off (line 1 in the table). You enter the room and frob S1. Now S1 is on and S2 is off (line 2 in the table). At this point, the output of the RequireAnyTrap is On, the output of All 1 is off, but the Inverter changes this to On. So now All2 is seeing On at both of its inputs, so it send out On to the controlled devices.
Now say that you walk across the room and leave, frobbing S2 on the way out. Now we move to line 4: both S1 and S2 are on. The RequireAnyTrap outputs On, All 1 outputs On, but now the Inverter changes that to Off, so All 2 is now seeing one On and one Off - so it sends an Off to the controlled objects.


For example, say that initially both switchs are off (line 1). You enter the room and frob S1. Now S1 is on and S2 is off - the output of the RequireAnyTrap is On, the output of All1 is off, but the Inverter changes this to On. So now All2 is seeing On at both of its inputs, so it send out On to the controlled devices. Now say that you walk across the room and leave, frobbing S2 on the way out. Now we move to line 4: S1 and S2 are on. The RequireAnyTrap outputs On, All1 outputs On, but now the Inverter changes that to Off, so All2 is now seeing one On and one Off - so it sends an Off to the controlled objects. Some time later you come back into the room via the door next to S1. Remember that S1 and S2 are still both On. You frob S1, moving from Line 3 to Line 4. This creates the same state as on line 2, All2 sends On to the controlled objects.
Some time later you come back into the room via the door next to S1. Remember that S1 and S2 are still both On. You frob S1, moving from line 4 to line 3 in the table.


The only fly in the ointment with this method is that the Inverter needs to be "primed" with an Off before the system works properly. This only needs to be done once at the start of the level.
The only fly in the ointment with this method is that the Inverter needs to be "primed" with a TurnOff before the system works properly. This only needs to be done once at the start of the level, and can be done as part of initialising other on-start effects (see [http://dromed.whoopdedo.org/dromed/on_at_start this page] at The Dromesday Book for how to do this).

Revision as of 21:46, 30 August 2011

Consider the situation where you have two doors into a room, each with a light switch next to it, or a switch at the top and bottom of a flight of stairs. Either switch needs to be able to control one or more common lights (say you want to be able to turn the lights on at one side of the room, walk to the door on the far side and turn the lights off with the switch next to that door). In real life, this trick is done using some clever wiring - I wanted to try doing it in dromed using nothing but fnords. What I ended up with is this (borrowing some symbols from digital electronics):

Tutorial-MultiSwitch.png

(As a side note, this is actually an implementation of an exclusive-OR gate..)

The "Any" object is a RequireAnyTrap (an OR gate), the two "All" objects are RequireAllTraps (AND gates) and Inv is an Inverter. S1 and S2 are the input switches, O is the output (which may be one or more objects). To set this up in Dromed:

  • Place your two switches, call them S1 and S2.
  • Add the objects you want to control - lights, doors, whatever.
  • Add one RequireAnyTrap fnord and rename it Any.
  • Add two RequireAllTrap fnords and call them All1 and All2.
  • Add one Inverter fnord, call it Inv.
  • Add a ControlDevice link from S1 to Any.
  • Add a ControlDevice link from S1 to All1.
  • Add a ControlDevice link from S2 to Any.
  • Add a ControlDevice link from S2 to All1.
  • Add a ControlDevice link from Any to All2 (line a on the diagram).
  • Add a ControlDevice link from All1 to Inv (line b on the diagram).
  • Add a ControlDevice link from Inv to All2 (line c on the diagram).
  • Add ControlDevice links from All2 to all the controlled objects.

To see how this works, have a look at this truth table:

  S1 S2 a b c out
1:OffOffOffOffOnOff
2:On OffOn OffOnOn
3:OffOn On OffOnOn
4:On On On On OffOff

For example, say that initially both switches are off (line 1 in the table). You enter the room and frob S1. Now S1 is on and S2 is off (line 2 in the table). At this point, the output of the RequireAnyTrap is On, the output of All 1 is off, but the Inverter changes this to On. So now All2 is seeing On at both of its inputs, so it send out On to the controlled devices.

Now say that you walk across the room and leave, frobbing S2 on the way out. Now we move to line 4: both S1 and S2 are on. The RequireAnyTrap outputs On, All 1 outputs On, but now the Inverter changes that to Off, so All 2 is now seeing one On and one Off - so it sends an Off to the controlled objects.

Some time later you come back into the room via the door next to S1. Remember that S1 and S2 are still both On. You frob S1, moving from line 4 to line 3 in the table.

The only fly in the ointment with this method is that the Inverter needs to be "primed" with a TurnOff before the system works properly. This only needs to be done once at the start of the level, and can be done as part of initialising other on-start effects (see this page at The Dromesday Book for how to do this).

Authors

  • gravatar The Watcher [userbureaucratsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+]