Functions
Use functions to create re-usable circuits with parameters. The default library lib.cst
uses functions for common circuit components like res
, cap
, etc.
Functions are executed at the current cursor point. When the function has completed execution, the current cursor point may have changed. The branch
command can be used before the function is called to restore the previous cursor point.
import lib
v5v = supply("net")
gnd = dgnd()
def my_pull_down(value):
wire down 100
add res(value)
wire down 100
to gnd
at v5v
wire down 100
branch:
my_pull_down(20k)
wire right 200
branch:
my_pull_down(10k)
wire right 200
branch:
my_pull_down(1k)
Function scope
Variables or values declared within a function will be scoped only within that function. Functions are able to access variables defined in an outer scope.
import lib
v5v = supply("5v")
gnd = dgnd()
my_cap = cap(100n)
def my_circuit():
wire down 100
add my_cap
wire down 100
to gnd
def my_circuit2():
my_cap = cap(200n)
wire down 100
add my_cap
wire down 100
to gnd
at v5v
wire down 100
branch:
my_circuit()
wire right 400
branch:
my_circuit2()