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:
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.
Functions ribbon tab → Wire manager.
Select your
Hallway light ONwire.Under Functions:, select the existing
DIGITAL_ONentry and click – to remove it.Click +. In the Wire function window:
Action:
Short downUser function:
DIGITAL_SWITCH
OK, and close the Wire manager.
Rename the wire to
Hallway light togglewhile 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 downand notShort up?Short downfires the moment the button goes in;Short upfires when it is released. For lighting,Short downfeels more responsive. For anything where you want to be sure the user meant it,Short upis 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:
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:
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.)Place another button icon, Connect it to button 2 of the GSB3-40, name it
Stair button.Function workspace tab → Functions ribbon tab → Add connection.
Drag from
Stair buttontoStair light. Turn Add connection off again.Wire manager → select the new wire → name it
Stair light 1 min→ +:Action:
Short downUser function:
DIGITAL_IMPULSE_1MIN
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:
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.
Functions ribbon tab → Function manager.
Click +. The right-hand panel becomes editable.
Fill in:
Name:
DIGITAL_IMPULSE_2MINFunction type:
DigitalSelect function:
Digital_Impulse_ON
Two parameters appear:
Digital delay (s) →
00:00:00Digital impulse time (s) →
00:02:00
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_2MINis reusable anywhere.STAIR_LIGHTis 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:
Wire manager → select
Hallway light toggle.+:
Action:
Long downUser function:
DIGITAL_OFF
OK, close, save, upload.
Now: short press toggles the light, long press always turns it off. Same button, same wire, two rules.
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:
Function manager → +
Name:
DIGITAL_OFF_AFTER_30SFunction type:
DigitalSelect function:
Digital delay switch OFFDigital 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:
Digital delay switch ON
switches on
Digital delay switch OFF
switches off
Digital delay switch value
toggles
What you learned
DIGITAL_SWITCHtoggles;DIGITAL_ONdoes notImpulse functions switch and switch back —
impulse timesets how longDigital_Impulse_ONignores a press while the output is already onYou 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
Build
DIGITAL_IMPULSE_10MINand put it on an outside light.Add
DIGITAL_ONonShort upto a wire that already hasDIGITAL_OFFonShort down, and work out what the light does. (Read the actions carefully before you upload.)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.