Skip to content

004 Button Pull-Up ​

004-button-pull.mc models a normally-high button input. The resistor pulls BUTTON_IN toward V3V3; pressing the normally open switch connects that node to GND.

text
V3V3 -> R_PULL -> BUTTON_IN
BUTTON_IN -> SW_USER.COM
SW_USER.NO -> GND

This is the first named intermediate signal. Repeating BUTTON_IN joins the resistor and switch statements at one electrical node. SW_USER.COM and SW_USER.NO use descriptive pin members: COM is the switch common pin and NO is the normally open contact.

bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 00-getting-started/004-button-pull.mc --lib mcode --pass1 --pass2
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 00-getting-started/004-button-pull.mc --lib mcode --viz -o 00-getting-started/004-button-pull.html

Source ​

text
// Example: Button Pull-Up
// Goal: Model a normally-high button input with a pull-up resistor.
// Library focus: SWITCH.MOM, RES, DC.

module main
{
    io BUTTON_IN
    io GND
    io V3V3

    DC.SRC PWR(3.3V, 100mA)
    RES R_PULL(10000R, 50V)
    SWITCH.MOM SW_USER

    PWR.1 -> V3V3
    PWR.2 -> GND

    // BUTTON_IN is high normally and is connected to ground when pressed.
    V3V3 -> R_PULL -> BUTTON_IN
    BUTTON_IN -> SW_USER.COM
    SW_USER.NO -> GND
}

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