# ButtonToggle

## `ButtonToggle` (FB)

FUNCTION\_BLOCK ButtonToggle

### Short description

> Switching element with button and central control.\
> Typical use: light pushbutton and light output.

### Representation

<figure><img src="https://2592874069-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQR4vCFzt6ixgsqlR3pdR%2Fuploads%2Fgit-blob-f3ba70e5f13e4fc63a147778782dcc38c344b4b1%2FButtonToggle_FB.png?alt=media" alt=""><figcaption></figcaption></figure>

### Interfaces

#### Inputs

| Name          | Data type | Value range | Initial value | Function               |
| ------------- | --------- | ----------- | ------------- | ---------------------- |
| *xButton*     | BOOL      |             |               | Input - control button |
| *xCentralOn*  | BOOL      |             |               | Central switch-on      |
| *xCentralOff* | BOOL      |             |               | Central switch-off     |

#### Outputs

| Name   | Data type | Value range | Initial value | Function        |
| ------ | --------- | ----------- | ------------- | --------------- |
| *xOut* | BOOL      |             |               | Enable - output |

#### Setpoints / Parameters

| Name            | Data type | Value range | Initial value | Function                |
| --------------- | --------- | ----------- | ------------- | ----------------------- |
| **xButtonVisu** | BOOL      |             | FALSE         | Function like *xButton* |

### Function description

#### General

The function block is basically used for the direct control of the enable - output *xOut* depending on the rising edges at the inputs *xButton* (= control button), *xCentralOn* (= central switch-on), *xCentralOff* (= central switch-off) and the setpoint / parameter **xButtonVisu**.\
Each rising edge at the input - control button *xButton* and / or at the setpoint / parameter **xButtonVisu** toggles the output *xOut* to the opposite state, provided no central control takes place.\
If no rising edges are detected, the state of the enable - output *xOut* does not change.

#### Truth table

| *xButton* or **xButtonVisu** | *xCentralOn*     | *xCentralOff*    | *xOut*                     | Note                                  |
| ---------------------------- | ---------------- | ---------------- | -------------------------- | ------------------------------------- |
| FALSE, TRUE, L/H             | FALSE, TRUE, L/H | FALSE, TRUE, L/H | unchanged                  | Inputs not active                     |
| L/H                          | FALSE, TRUE, L/H | FALSE, TRUE, L/H | FALSE > TRUE, TRUE > FALSE | State change at the output            |
| FALSE, TRUE, L/H             | L/H              | FALSE, TRUE, L/H | TRUE                       | Central switch-on                     |
| FALSE, TRUE, L/H             | FALSE, TRUE, L/H | L/H              | FALSE                      | Central switch-off                    |
| L/H                          | L/H              | FALSE, TRUE, L/H | TRUE                       | Central switch-on (higher priority)   |
| L/H                          | L/H              | L/H              | FALSE                      | Central switch-off (highest priority) |

Legend: L/H … rising edge, H/L … falling edge

### CODESYS

InOut:

| Scope       | Name          | Type   | Initial |
| ----------- | ------------- | ------ | ------- |
| Input       | `xButton`     | `BOOL` |         |
| Input       | `xCentralOn`  | `BOOL` |         |
| Input       | `xCentralOff` | `BOOL` |         |
| Input Const | `xButtonVisu` | `BOOL` | FALSE   |
| Output      | `xOut`        | `BOOL` |         |
