For the complete documentation index, see llms.txt. This page is also available as Markdown.

Tutorial 2 — toggles, impulses and delays

Part 2 — Tutorials. Continues the project from Tutorial 1.


What you will build

Four improvements to the hallway you built last chapter:

Behaviour
You will learn

1

One button toggles the light

DIGITAL_SWITCH

2

A staircase light that switches itself off

impulse functions and impulse time

3

A custom two-minute version

defining your own function

4

Long-press turns everything off

one button, two actions

Open your Tutorial project before you start.


1. Toggle — one button, on and off

In Tutorial 1 the button only ever turned the light on. Pressing it again did nothing, because Digital switch ON means exactly that.

Toggle is a different function: if it is on, turn it off; if it is off, turn it on.

  1. Functions ribbon tab → Wire manager.

  2. Select your Hallway light ON wire.

  3. Under Functions:, select the existing DIGITAL_ON entry and click to remove it.

  4. Click +. In the Wire function window:

    • Action: Short down

    • User function: DIGITAL_SWITCH

  5. OK, and close the Wire manager.

  6. Rename the wire to Hallway light toggle while you are there — wire names matter once there are two hundred of them.

Save and upload ([☰]Save to central unit). Press the button repeatedly: on, off, on, off.

Why Short down and not Short up? Short down fires the moment the button goes in; Short up fires when it is released. For lighting, Short down feels more responsive. For anything where you want to be sure the user meant it, Short up is safer. Both are correct — pick deliberately.


2. A staircase light

An impulse switches something on and then off again by itself, after a time you choose. That is the classic staircase light: press once, get light for long enough to reach the top.

The default project already has these:

Function
On for

DIGITAL_IMPULSE_1S

1 second

DIGITAL_IMPULSE_5S

5 seconds

DIGITAL_IMPULSE_1MIN

1 minute

DIGITAL_IMPULSE_5MIN

5 minutes

Wire one up to the second button on your GSB3-40:

  1. Design workspace tab → place another output icon and Connect it to the SA3-02M's second output. Name it Stair light. (If your relay has only one output, reuse the hallway light — the behaviour is the same.)

  2. Place another button icon, Connect it to button 2 of the GSB3-40, name it Stair button.

  3. Function workspace tab → Functions ribbon tab → Add connection.

  4. Drag from Stair button to Stair light. Turn Add connection off again.

  5. Wire manager → select the new wire → name it Stair light 1 min+:

    • Action: Short down

    • User function: DIGITAL_IMPULSE_1MIN

  6. OK, close, save, upload.

Press button 2. The light comes on, stays on for a minute, and goes out by itself.

What impulse actually does

There are three impulse functions and the difference matters:

Function
Behaviour

Digital_Impulse_ON

If the output is already on, nothing happens. If it is off: wait delay, switch on, wait impulse time, switch off.

Digital_Impulse_OFF

The mirror image. If already off, nothing happens. If on: wait delay, switch off, wait impulse time, switch on.

Digital impulse

Ignores the current state. Waits delay, flips the output, waits impulse time, flips it back.

Both parameters accept anything from 0 seconds to 24 hours.

The predefined DIGITAL_IMPULSE_* functions are all built on Digital_Impulse_ON with a delay of zero. That is why pressing the button again mid-cycle does not restart the timer — the output is already on, so the function does nothing.

Want a re-triggerable staircase light — where each press restarts the minute? An impulse will not do it. Use a timer instead (Tutorial 8).


3. Define your own function

One minute is too short, five is too long. You want two. Nothing predefined does that, so make it.

  1. Functions ribbon tab → Function manager.

  2. Click +. The right-hand panel becomes editable.

  3. Fill in:

    • Name: DIGITAL_IMPULSE_2MIN

    • Function type: Digital

    • Select function: Digital_Impulse_ON

  4. Two parameters appear:

    • Digital delay (s)00:00:00

    • Digital impulse time (s)00:02:00

  5. Click to save. It joins the list on the left.

Now swap it onto the wire: Wire manager → the stair wire → remove DIGITAL_IMPULSE_1MIN, add DIGITAL_IMPULSE_2MIN on Short down. Save, upload, test.

Name functions after what they do, not where you used them. DIGITAL_IMPULSE_2MIN is reusable anywhere. STAIR_LIGHT is not — and in a year nobody will remember what it does. The predefined names follow this convention; follow it too.

The delay parameter

You skipped over delay by leaving it at zero. It is genuinely useful: a delay of 00:00:03 on an impulse means wait three seconds, then give a minute of light.

Combine that with Digital delay switch OFF and you can build a corridor that lights ahead of someone and goes dark behind them.


4. One button, two behaviours

A button has four actions. Nothing stops you using several on the same wire — this is how one switch does more than one job.

Add a long-press "everything off" to your toggle wire:

  1. Wire manager → select Hallway light toggle.

  2. +:

    • Action: Long down

    • User function: DIGITAL_OFF

  3. OK, close, save, upload.

Now: short press toggles the light, long press always turns it off. Same button, same wire, two rules.

Action
Means
Fires when
Typical use

Short down

short press

the button goes down

the normal action

Short up

short release

it comes back up

when you want confirmation on release

Long down

long press

still held after ~1.5 s

a second function — "all off", "scene"

Long up

long release

released after a long press

ending a held action, e.g. stop dimming

Permanent actions

repeatedly, driven by the CU

continuous behaviour while a state holds

Long up looks pointless until you dim a light by holding a button — Tutorial 3 uses exactly that: Long down starts the brightness climbing and Long up stops it.


5. Delayed off

One more useful pattern. Digital delay switch OFF turns something off after a delay — it does not touch it now.

Make a DIGITAL_OFF_AFTER_30S:

  1. Function manager+

    • Name: DIGITAL_OFF_AFTER_30S

    • Function type: Digital

    • Select function: Digital delay switch OFF

    • Digital delay (s): 00:00:30

Put it on a wire with Short down and the light goes off half a minute after you press. Combine it with a motion sensor rather than a button and you have the "keep the light alive while there is movement" behaviour from the worked example in Chapter 2.

The three delay functions:

Function
Effect after the delay

Digital delay switch ON

switches on

Digital delay switch OFF

switches off

Digital delay switch value

toggles


What you learned

  • DIGITAL_SWITCH toggles; DIGITAL_ON does not

  • Impulse functions switch and switch back — impulse time sets how long

  • Digital_Impulse_ON ignores a press while the output is already on

  • You define your own functions in Function manager, and name them after what they do

  • One wire carries several actions — that is how one button does several jobs

  • Delay functions act later, not now


Try this before moving on

  1. Build DIGITAL_IMPULSE_10MIN and put it on an outside light.

  2. Add DIGITAL_ON on Short up to a wire that already has DIGITAL_OFF on Short down, and work out what the light does. (Read the actions carefully before you upload.)

  3. Open Wire manager and give every wire a real name. Future you will be grateful.


Next: Chapter 7 — Tutorial 3: dimming — analog outputs, levels, and ramps.