Pre-installed application - controlling via digital inputs
Digital inputs of the router can be used to change the running direction of the counter (see here) or reset it.
Controlling the running direction
The running direction is defined by the flag flag4 - Counter_Direction. If the flag has the value 1, the counter will be increased each second by 1; if the flag has the value 0, the counter is stopped; if the flag has the value -1, the counter will be decreased each second by 1.
Digital input IN1 of the router sets the value of the flag.
To achieve this, two events are configured. One that increases the flag flag4 - Counter_Direction by 1 with each closure of the digital input IN1 (connecting IN1 to VCC), and one that sets flag4 - Counter_Direction to -1 again with each exceeding of the value 1 by this flag. Thus, the counter cycles with each closure of the inputs between -1 (decrease counter), 0 (stop counter) and 1 (increase counter).
Menu Data points → Digital I/Os
The data point input1 for digital input 3.1 of the router (IN1) is added here.
Menu Events → edit Input_Counter_Direction_Change ()
An event is added here, which triggers an action with each change of the data point input1 - Counter_Direction to HIGH (closing the digital input IN1). The action increments the value of data point flag4 - Counter_Direction by the value 1.
Menu Events → edit Counter_Direction_Rollover_Check ()
Since only the values -1, 0 1nd 1 are allowed for the counter direction, the following event sets the counter direction back to -1 if it exceeds 1. An event is added here, which triggers an action with each exceeding of the value by the data point flag4 - Counter_Direction. The action sets the value of data point flag4 - Counter_Direction to the value -1.
Resetting the counter
Digital input IN2 of the router resets the counter.
To achieve this, an event is configured, which (re)sets the flag flag3 - Counter to 0 with each closure of the digital input IN2 (connecting IN1 to VCC).
Menu Data points → Digital I/Os
The data point input2 for digital input 3.2 of the router (IN2) is added here.
Menu Events → edit Input_Counter_Reset ()
An event is added here, which triggers an action with each change of the data point input2 - Counter_Reset to HIGH (closing the digital input IN2). This action sets the value of data point flag3 - Counter to the value 0.