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 --pass2Generate 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.htmlSource
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
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21