Skip to content

041 LED Indicator Function ​

041-led-indicator-function.mc defines a two-pin STATUS_LED and gives it an Indicator method for connecting an already current-limited signal:

text
func Indicator([limited_signal, ground])
{
    limited_signal -> ANODE
    CATHODE -> ground
}
  • func declares a function inside the component.
  • [limited_signal, ground] is one vector parameter that destructures into two node names for the method body. Their values are supplied by the call in module main.
  • Inside a component method, bare pin names such as ANODE and CATHODE refer to those pins on the current component instance. The two statements therefore wire the current-limited signal to the LED anode and the LED cathode to ground.
  • GPIO_STATUS -> R_LIMIT.1 connects the control signal to the resistor's first physical pin. D_STATUS.Indicator([R_LIMIT.2, GND]) passes the resistor's other pin and ground as the method's vector argument.
  • The dot in D_STATUS.Indicator(...) selects a method on the D_STATUS instance, and the call parentheses contain its arguments.

The explicit R_LIMIT.1 and R_LIMIT.2 connections keep the resistor as a real two-pin series device. The resolved circuit is GPIO_STATUS, R_LIMIT, D_STATUS, then GND. This example intentionally avoids return values, typed parameters, and inline construction.

bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 04-functions-and-reuse/041-led-indicator-function.mc --lib mcode --pass1 --pass2
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 04-functions-and-reuse/041-led-indicator-function.mc --lib mcode --viz -o 04-functions-and-reuse/041-led-indicator-function.html

Source ​

text
// Example: LED Indicator Function
// Goal: Connect a current-limited status LED with a reusable method.
// Language focus: func, parameters, component pin access, method calls.

component STATUS_LED
{
    name = "Status LED"
    pins = [
        io [1, 2] = DIO{A, K}   // A = anode, K = cathode (DIO face adoption)
    ]

    func Indicator([limited_signal, ground])
    {
        limited_signal -> this.A
        this.K -> ground
    }
}

module main
{
    io GND
    io GPIO_STATUS

    STATUS_LED D_STATUS
    RES R_LIMIT(330R, 50V)

    // The resistor remains a two-pin series device outside the method.
    GPIO_STATUS -> R_LIMIT.1
    D_STATUS.Indicator([R_LIMIT.2, GND])
}

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