|
Create a switch
function
Introduction
In this tutorial you will learn how
to create a small function that works
as a switch. The switch can be used
to turn things on and off (e.g. a
display) when a signal is sent to
it.
Software used: WireFusion
3.2.14
Download
this WireFusion project (zip:
13 kb)
Test
this project >>>
Step 1 -
Insert a Boolean object
Insert a Boolean object
(found in Objects > Data) to a
new empty project. When its dialog
opens, keep the checkbox value True
(Yes) marked and close
the dialog.

Step 2 -
Insert an If object
Insert an If object
(found in Objects > Logic).

Step 3 -
Insert a Boolean Operation object
Insert a Boolean Operation
object (found in Objects > Logic).
When its dialog opens, close
it without doing any changes.

Step 4 -
Insert an Image object
Insert an Image object
(found in Objects > Multimedia).
When its dialog opens, close
it without doing any changes.

The image object will here act as
a display and we want it to be turned
off at presentation startup. Therefore,
deactivate the Image
by unmarking the Activate
checkbox next to the Image
object found in the Layer view.

Step 5 -
Insert a Button object
Insert a Button object
(found in Objects > Widgets). When
its dialog opens, change the
button label to "On/Off"
and then close the dialog.

Step 6 -
Connecting Button and Boolean
We want to send the stored Boolean
value in the Boolean object
when we press the button. Therefore,
make the following connection.
Connect:
'Button 1' > Out-ports > Button
Clicked
to
'Boolean 1' > In-ports > Push
Value
This means that when the button is
clicked, it will push the current
Boolean value (which here is set to
True at startup).

Step 7 -
Connecting Boolean and If
When the Boolean value has been sent
out from the Boolean object
we want the value to enter the If
object, which then evaluates if the
value is true or false. Therefore,
make the following connection.
Connect:
'Boolean 1' > Out-ports > Value
Pushed [Boolean]
to
'If 1' > In-ports > Boolean
Value [Boolean]

Step 8 -
Connecting If and Image
If the incoming value to the If
object is true, then the If
object will send out a signal through
its True out-port. If the incoming
value is false, then the If
object will send out a signal through
the False out-port instead.
To activate the image (i.e. turn
it on) when a true value is fired,
make the following connection.
Connect:
'If 1' > Out-ports > True [Boolean]
to
'Image 1' > In-ports > Activate
To deactivate the image (i.e. turn
it off) when a false value is fired,
make the following connection.
Connect:
'If 1' > Out-ports > False[Boolean]
to
'Image 1' > In-ports > Deactivate

Step 9 -
Change the Boolean state
We need to switch the state in the
Boolean object and this is
done with help of the Boolean Operation
object.
Connect:
'Boolean 1' > Out-ports > Value
Pushed
to
'Boolean Operations 1' > In-ports
> Set a [Boolean]
The NOT operation inverts
the incoming value from True
to False (or from False
to True).

To Send back the inverted
value to the Boolean object,
make the following connection.
Connect:
'Boolean Operations 1' > Out-ports
> NOT a [Boolean]
to
'Boolean 1' > In-ports > Set
Value [Boolean]
The inverted value is now sent to
the Boolean object, which now
changes its states.

The action event looks like this:
1. Press the button to trigger the
Boolean object to send out
its stored value.
2. The stored Boolean value is sent
to the If object.
3. The stored Boolean value is also
sent to the Boolean Operation
object.
4. The Boolean value is inverted and
sent back to the Boolean object
and is stored there.
5. If object evaluates the
incoming Boolean value (from point
2).
6. If Boolean value is true, then
the If object's True port is
fired, else the False port is fired.
Step 10
- Test
You have now created a switch function!
Preview (F9) the presentation
and press the On/Off button
repeatedly to turn the image on and
off.

End of lesson!
|