Skip to content

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_SENSOR creates a reusable component type. It does not create a physical part until TWO_PIN_SENSOR U_SENSOR appears in module 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 = VCC and 2 = GND give readable member names to physical pins 1 and 2. The module can then connect U_SENSOR.VCC and U_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.html

Source ​

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
}

MCode Bench is the public face of the MCode stack. Closed capabilities are served through the MCode gateway.