USING System.Counters;
PROGRAM SampleProgram
VAR_EXTERNAL
pushButton : BOOL;
switch : BOOL;
light : BOOL;
END_VAR
VAR
count : Counter := (presetValue := 10);
END_VAR
VAR_TEMP
total : INT;
END_VAR
// increment counter by 1 for every push of the button
count(up := pushButton, down := switch);
// pushButton created a rising edge 10 times more often than switch
IF count.presetReached THEN
light := true;
END_IF;
IF count.value > 100 THEN
count(reset := true); // reset the current value to 0
count(reset := false); // set reset to false, otherwise the count will stay 0 regardless of other inputs
END_IF;
END_PROGRAM