Skip to main content

Circuit paths

There are a few keywords that can be used to split off or connect multiple circuit paths. This is useful for building complex circuits.

A brief summary of the keywords:

KeywordDescription
branchSplit off paths in separate blocks at the location before the branch
joinConnect separate paths into the current location after the join block(s)
parallelConnect separate paths with the same starting and ending points
pointConnect separate paths at the current location. Use at point and to point to reference the location of the point

branch

The branch command allows the circuit to split off from a given insertion point. After all branch blocks are executed, the pre-branch insertion point is restored.

What happens within a branch block is indicated by an indent.

Example:

from "std" import *

v5v = supply("5V")
gnd = dgnd()

at v5v
wire down 100 # Point A
branch:
wire down 100 # Wire is added within this branch.
add res(20k)
wire down 200
to gnd

wire right 300 down 200 # Wire is added after point A
add cap(100n)
wire down 100
to gnd
line 6:15VComponent R1: line 10:5R120kline 12:8GNDComponent C1: line 15:1C1100nline 17:4GND

In the above example, the branch splits off to create the path with the res(20k). When this path in this branch block has completed execution, the insertion point is reset back to the the pre-branching state. In this case, it is after the wire down 20 from v5v.

Consecutive branch blocks will share the same branching point.

warning

It is possible to have branches within branches, but bear in mind that readability might be affected.

join

This keyword connects multiple different paths to a single insertion point.

Example:

from "std" import *

v5v = supply("5V")
gnd = dgnd()

def led_with_res(color):
add led(color) pin 2
wire right 100
add res(360)
wire right 100

join:
# path 1
at gnd
wire right 100
led_with_res("red")

join:
# path 2
at gnd
wire right 100
led_with_res("green")
wire up 500

# join point
wire up 100
to v5v
line 14:5GNDComponent D1_1: line 7:512D1_1redComponent R1_1: line 9:5R1_1360line 27:45VComponent R1_2: line 9:5R1_2360Component D1_2: line 7:512D1_2greenline 20:5GND

In the above example, the two circuit points are connected together at the join point.

Consecutive join blocks will share the same join point. The position of the join position is determined by the path in the very first block.

parallel

This keyword connects multiple different paths to have the same initial and end points.

Example:

from "std" import *

v5v = supply("5V")
gnd = dgnd()

at v5v
wire down 100

# this is the initial point

for i in range(0, 3):
parallel:
wire right (i*200) down 100
add diode("RED")
wire down 100
add res(1k)
wire down 100

if i > 0:
wire auto


wire down 100
to gnd
line 6:15VComponent D1_1: line 14:912D1_1Component R1_1: line 16:9R1_11kline 24:4GNDComponent R1_2: line 16:9R1_21kComponent D1_2: line 14:912D1_2Component R1_3: line 16:9R1_31kComponent D1_3: line 14:912D1_3

point block

This keyword creates a reference at the current location where the point block is first declared. When at point or to point are executed within the point block, the location of the point will be used.

Example:

from "std" import *

v5v = supply("5V")
gnd = dgnd()

at v5v
wire down 100
add res(360)
wire down 100

point:
at v5v
wire down 100
add res(360)
wire down 100

branch:
wire left 500
to point

wire down 100
add res(360)
wire down 200
to gnd

at point
wire right 1000 down 100
add res(360)
wire down 200
to gnd

wire down 100
add led("red") pin 2
wire down 100
to gnd
line 6:15VComponent R1: line 8:1R1360line 19:12Component R4: line 28:5R4360line 30:8GNDComponent D1: line 33:112D1redline 35:4GNDComponent R3: line 22:5R3360line 24:8GNDComponent R2: line 14:5R2360line 12:55V

If at point or to point are called within an inner block, then the location of the nearest point: block will be used.

warning

The usage of the point block is very similar to the point keyword, but have slightly different usage.