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.

  1. 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.
  2. Create a new Function Block and rename it to VISUSET.
  3. Define the database with autocompletion for switch.
  4. Set the input DIS to TRUE or negate it.
  5. At the input SET, create a new Function Block named N. This outputs a pulse on a falling edge of the pushbutton.
  6. Then, enter the name N1 for the database of the Function Block N.
  7. 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.
  8. 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.
  9. 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.
  10. 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.