Skip to main content

Functions

Use functions to create re-usable circuits with parameters. The default library std.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.

from "std" import *
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)
line 11:1netComponent R1_1: line 7:5R1_120kline 9:8GNDComponent R1_2: line 7:5R1_210kline 9:8GNDComponent R1_3: line 7:5R1_31kline 9:8GND

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.

from "std" import *
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()


line 21:15vComponent C1: line 5:1C1100nline 11:8GNDComponent C2: line 14:5C2200nline 19:8GND