031 Named Pins Component
031-named-pins-component.mc defines a tiny two-pin sensor and instantiates it in module main. This is the first local component definition in the tutorial:
text
component TWO_PIN_SENSOR
{
name = "Two-Pin Sensor"
pins = [
1 = VCC
2 = GND
]
}component TWO_PIN_SENSORcreates a reusable component type. It does not create a physical part untilTWO_PIN_SENSOR U_SENSORappears inmodule main.name = "Two-Pin Sensor"assigns a display attribute. Quotation marks delimit a string value.pins = [...]declares the component's physical pins. Square brackets contain the pin entries.1 = VCCand2 = GNDgive readable member names to physical pins 1 and 2. The module can then connectU_SENSOR.VCCandU_SENSOR.GND.
The circuit is only a sensor powered from a 3.3 V source, but it separates the component definition from the instance that uses it.
bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 03-define-components-and-interfaces/031-named-pins-component.mc --lib mcode --pass1 --pass2
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 03-define-components-and-interfaces/031-named-pins-component.mc --lib mcode --viz -o 03-define-components-and-interfaces/031-named-pins-component.htmlSource
text
// Example: Named Pins Component
// Goal: Define and instantiate a small component with readable pin names.
// Language focus: component, attributes, pins.
component TWO_PIN_SENSOR
{
name = "Two-Pin Sensor"
pins = [
1 = VCC
2 = GND
]
}
module main
{
io GND
io V3V3
DC.SRC PWR(3.3V, 20mA)
TWO_PIN_SENSOR U_SENSOR
PWR.1 -> V3V3
PWR.2 -> GND
V3V3 -> U_SENSOR.VCC
U_SENSOR.GND -> GND
}