Skip to main content

Your first program

The "hello world" of hardware is a blinking light. In Runeweave it takes three nodes and two wires.

┌─────────────┐ ┌─────────────┐ ┌──────────────────┐
│ clock │ │ flip-flop │ │ digital-write │
│ IVAL 0.25 │ TICK ─┤► TGL MEM ├──────►│ SIG PORT D13 │
└─────────────┘ └─────────────┘ └──────────────────┘
  1. sdp/time/clock sends a pulse on TICK every IVAL seconds. Set IVAL to 0.25.
  2. sdp/logic/flip-flop flips its MEM output between on and off each time its TGL input gets a pulse.
  3. sdp/gpio/digital-write drives the pin in PORT to the value of SIG. Set PORT to the pin your light is on.

Wire TICK to TGL, and MEM to SIG. Every quarter of a second the clock ticks, the flip-flop flips and the light follows: it blinks twice a second.

On disk​

Saved, this patch is a short text file, patches/main/patch.rwp. You never have to edit it by hand, but it shows there's no magic: one line per node and one per wire.

{"format":1}
{"kind":"node","id":"clock","type":"sdp/time/clock","at":[0,0],"pins":{"IVAL":{"value":"0.25"}}}
{"kind":"node","id":"flip","type":"sdp/logic/flip-flop","at":[2,1]}
{"kind":"node","id":"led","type":"sdp/gpio/digital-write","at":[4,2],"pins":{"PORT":{"value":"D13"}}}
{"kind":"link","id":"link-0","from":{"node":"clock","pin":"TICK"},"to":{"node":"flip","pin":"TGL"}}
{"kind":"link","id":"link-1","from":{"node":"flip","pin":"MEM"},"to":{"node":"led","pin":"SIG"}}

Try next​

  • Replace the clock with sdp/gpio/digital-read on a button pin and sdp/logic/pulse-on-true, so the light toggles each time you press.
  • Add sdp/logic/not between the flip-flop and the light, and see the blink invert.