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:
| Keyword | Description |
|---|---|
branch | Split off paths in separate blocks at the location before the branch |
join | Connect separate paths into the current location after the join block(s) |
parallel | Connect separate paths with the same starting and ending points |
point | Connect 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
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.
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
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
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
If at point or to point are called within an inner block, then the location of the nearest point: block will be used.
The usage of the point block is very similar to the point keyword, but have slightly different usage.