In this Function Block example in Structured text we will shift the index in array per 1 second and set the output bit.
![[203128%2F9160286%2Fmceclip0]](https://d28lcup14p4e72.cloudfront.net/203128%2F9160286%2Fmceclip0.png)
VAR_TEMP
i : INT;
END_VAR
(* Timer initialization *)
T1(IN := IN, PT := T#1s);
IF T1.Q THEN
(* Set the current bit to TRUE *)
bitArray[index] := TRUE;
(* Increment the index *)
index := index + 1;
(* Check if all bits are TRUE *)
IF index >= 9 THEN
(* Reset all bits to FALSE *)
FOR i := 0 TO 7 DO
bitArray[i] := FALSE;
END_FOR;
(* Reset the index *)
index := 0;
END_IF;
(* Update the output variables *)
Bit0 := bitArray[0];
Bit1 := bitArray[1];
Bit2 := bitArray[2];
Bit3 := bitArray[3];
Bit4 := bitArray[4];
Bit5 := bitArray[5];
Bit6 := bitArray[6];
Bit7 := bitArray[7];
(* Reset the timer *)
T1(IN := FALSE);
T1(IN := IN);
END_IF;
Here is other version that set the bit to False with if statement.
VAR_TEMP
i : INT;
END_VAR
(* Timer initialization *)
T1(IN := IN, PT := T#1s);
IF T1.Q THEN
(* Set the current bit to TRUE *)
bitArray[index] := TRUE;
IF index > 0 THEN
bitArray[0] := False;
END_If;
IF index > 1 THEN
bitArray[1] := False;
END_IF;
IF index > 2 THEN
bitArray[2] := False;
END_IF;
IF index > 3 THEN
bitArray[3] := False;
END_IF;
IF index > 4 THEN
bitArray[4] := False;
END_IF;
IF index > 5 THEN
bitArray[5] := False;
END_IF;
IF index > 6 THEN
bitArray[6] := False;
END_IF;
IF index > 7 THEN
bitArray[7] := False;
END_IF;
(* Increment the index *)
index := index + 1;
(* Check if all bits are TRUE *)
IF index >= 9 THEN
(* Reset all bits to FALSE *)
FOR i := 0 TO 7 DO
bitArray[i] := FALSE;
END_FOR;
(* Reset the index *)
index := 0;
END_IF;
(* Update the output variables *)
Bit0 := bitArray[0];
Bit1 := bitArray[1];
Bit2 := bitArray[2];
Bit3 := bitArray[3];
Bit4 := bitArray[4];
Bit5 := bitArray[5];
Bit6 := bitArray[6];
Bit7 := bitArray[7];
(* Reset the timer *)
T1(IN := FALSE);
T1(IN := IN);
END_IF;