# Simple Examples and Patterns

Source: https://rungs.dev/docs/structured-text/simple-examples-and-patterns

> Reusable Structured Text patterns and worked examples in rungs.dev — motor start/stop, latching, edge detection, scaling, and other common PLC programming tasks.

This section provides simple, reusable logic patterns for common PLC programming tasks in Structured Text (ST).

## 1. Basic Motor Start/Stop Logic [#1-basic-motor-startstop-logic]

```iecst
// Start motor if Start button is pressed and Stop is not
IF Start_Button AND NOT Stop_Button THEN
    Motor_Run := 1;
ELSE
    Motor_Run := 0;
END_IF;
```

Or, simplified:

```iecst
Motor_Run := Start_Button AND NOT Stop_Button;
```

## 2. Latched Motor Control (Set/Reset Pattern) [#2-latched-motor-control-setreset-pattern]

```iecst
// Latch motor ON when Start is pressed
IF Start_Button THEN
    Motor_Latch := 1;
END_IF;

// Unlatch motor when Stop is pressed
IF Stop_Button THEN
    Motor_Latch := 0;
END_IF;

// Run motor based on latch state
Motor_Run := Motor_Latch;
```

## 3. Analog Threshold Control [#3-analog-threshold-control]

```iecst
// Turn on fan when temperature exceeds 60.5°C
IF Temperature > 60.5 THEN
    Fan := 1;
ELSE
    Fan := 0;
END_IF;
```

## 4. Mode Selector with CASE [#4-mode-selector-with-case]

```iecst
CASE Mode OF
    1: Operation := 'Auto';
    2: Operation := 'Manual';
    3: Operation := 'Maintenance';
ELSE
    Operation := 'Unknown';
END_CASE;
```

> **IDEA**
>
> **Practice**
>
> Try a timing pattern in the [Flasher exercise](https://rungs.dev/exercises/flasher) — blink an output one second on, one second off while enabled.