# MCIO 1-5 - example

## `F_IsXOR`

```
---------------------------------
FUNCTION F_IsXOR : BOOL
VAR_INPUT
    x1 : BOOL;
    x2 : BOOL;
END_VAR
VAR
END_VAR
---------------------------------
IF x1 = x2 THEN
    F_IsXOR := FALSE;
ELSE
    F_IsXOR := TRUE;
END_IF
---------------------------------
```

## `FB_LED`

```
---------------------------------
FUNCTION_BLOCK FB_LED
VAR_INPUT
    inp1 : BOOL;
    inp2 : BOOL;
END_VAR
VAR_OUTPUT
    out1 : BOOL;
    out2 : BOOL;
    out3 : BOOL;
    out4 : BOOL;
END_VAR
VAR
    count : DINT;
    blink : BOOL;
END_VAR
---------------------------------
count := count + 1;

blink := F_IsXOR (x1:=inp1, x2:=inp2);

IF blink THEN
    out1 := count MOD 2 = 0;
    out2 := count MOD 8 = 0;
    out3 := count MOD 32 = 0;
    out4 := count MOD 128 = 0;
ELSE
    out1 := FALSE;
    out2 := FALSE;
    out3 := FALSE;
    out4 := FALSE;
END_IF
---------------------------------
```

## `MAIN`

```
---------------------------------
PROGRAM MAIN
VAR
    toyLed : ARRAY [0..2] OF FB_LED;

    btn_1 AT %I* : BOOL;
    btn_2 AT %I* : BOOL;

    o_ch1_1 AT %Q* : BOOL;
    o_ch1_2 AT %Q* : BOOL;
    o_ch1_3 AT %Q* : BOOL;
    o_ch1_4 AT %Q* : BOOL;

    o_ch2_1 AT %Q* : BOOL;
    o_ch2_2 AT %Q* : BOOL;
    o_ch2_3 AT %Q* : BOOL;
    o_ch2_4 AT %Q* : BOOL;

    o_ch3_1 AT %Q* : BOOL;
    o_ch3_2 AT %Q* : BOOL;
    o_ch3_3 AT %Q* : BOOL;
    o_ch3_4 AT %Q* : BOOL;
END_VAR
---------------------------------
toyLed[0](inp1:=btn_1, inp2:=FALSE, out1=>o_ch1_1, out2=>o_ch1_2, out3=>o_ch1_3, out4=>o_ch1_4);

toyLed[1](inp1:=FALSE, inp2:=btn_2, out1=>o_ch2_1, out2=>o_ch2_2, out3=>o_ch2_3, out4=>o_ch2_4);

toyLed[2](inp1:=btn_1, inp2:=btn_2, out1=>o_ch3_1, out2=>o_ch3_2, out3=>o_ch3_3, out4=>o_ch3_4);
---------------------------------
```
