Skip to content

215 RGB LED PWM ​

215-rgb-led-pwm.mc describes a common-cathode RGB LED driven by three PWM signals.

PWM_RED, PWM_GREEN, and PWM_BLUE are output nodes from a controller that is not modeled here; the controller also supplies the shared GND connection. Each PWM node drives one LED anode through its own current-limiting resistor, and D_RGB.COMMON_CATHODE returns to GND.

Parse 215-rgb-led-pwm.mc:

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

Generate HTML for 215-rgb-led-pwm.mc:

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

Source ​

text
// Example: RGB LED PWM
// Goal: Connect three control signals to an RGB LED.
// Library focus: LED.RGB, RES, PWM.

module main
{
    io GND
    io PWM_BLUE
    io PWM_GREEN
    io PWM_RED

    LED.RGB D_RGB(2.0V, 3.2V, 3.2V, 20mA)
    RES R_RED(220R, 50V)
    RES R_GREEN(220R, 50V)
    RES R_BLUE(220R, 50V)

    PWM_RED -> R_RED -> D_RGB.RED_ANODE
    PWM_GREEN -> R_GREEN -> D_RGB.GREEN_ANODE
    PWM_BLUE -> R_BLUE -> D_RGB.BLUE_ANODE
    D_RGB.COMMON_CATHODE -> GND
}

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