A Light Switch
This example explains how to simply switch a light using the Function Block VISUSET.
Tip: The program can be downloaded and imported here:
example_switch.antobj
Function Principle
To switch a light using a pushbutton, the Function Block VISUSET controls it via the visualization variable switch. This has the advantage that the state is stored in the VISU Function Block. If this were implemented with a FlipFlop or a SET/RESET Function Block, the light could no longer communicate with the visualization without significant effort.
Basics
First, a new peripheral device of type
Light (found under Actuators ▸ Lights) is inserted into the
Structure and then clicked on
Apply in the Explorer.
After opening the element, click on
Edit to begin with the following steps.
- Add a new
Network above the existing Function Block VISU. You may need to move the network up with the
arrow symbols. This increases the performance of the program as the calculation is performed before the output out.switch.
- Create a new Function Block and rename it to VISUSET.
- Define the database with autocompletion for switch.
- Set the input DIS to TRUE or negate it.
- At the input SET, create a new Function Block named N. This outputs a pulse on a falling edge of the pushbutton.
- Then, enter the name N1 for the database of the Function Block N.
- At the input CLK of the Function Block N, write in.Tr1. If you want to assign multiple pushbuttons, you can add an OR Function Block before the input CLK.
- Now, write the same value out.switch at the first input ➜ of the Function Block VISUVAR as at the output of the Function Block VISU.
- To change the state when a pushbutton is triggered, this input must now be negated. You can double-click the input; the negation will then be indicated by a circle.
- Now you can test the application by clicking on
Apply and then on
Preview.
Note: After the modification, the output can still be controlled via the visualization. In addition, the state is synchronized via feedback.