Skip to content

212 Button Input ​

212-button-input.mc describes a normally high push-button input.

PWR creates the V3V3 and GND rails. R_PULL connects from V3V3 to the BUTTON_IN node, so the input is high when the button is open. SW_USER connects BUTTON_IN to GND when pressed, pulling the input low.

Parse 212-button-input.mc:

bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 21-digital-io-recipes/212-button-input.mc --lib mcode --pass1 --pass2

Generate HTML for 212-button-input.mc:

bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 21-digital-io-recipes/212-button-input.mc --lib mcode --viz -o 21-digital-io-recipes/212-button-input.html

Source ​

text
// Example: Button Input
// Goal: Connect a momentary switch to a digital input.
// Library focus: SWITCH.MOM, RES, GPIO, DC.

module main
{
    io BUTTON_IN
    io GND
    io V3V3

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

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

    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.