modelLedFade

GP0 drives an LED in PWM (machine.PWM) at 1 kHz: the duty cycle rises from 0 to 100 % in 1 s, then falls back to 0 in 1 s

Extends from Modelica.Icons.Example (Icon for runnable examples).

Information

Demonstrator (outside the verification scenarios): the script pwm_led_fade.py sets GP0 as a 1 kHz PWM output, waits 0.5 s, raises the duty cycle from 0 to 100 % in 1000 steps of 1 ms (duty_u16() called at each step), waits 0.5 s, lowers it back to 0 the same way, then releases the pin (deinit()). Unlike Examples.Pwm.Led, where the duty cycle is set once, it changes here while running: each call to duty_u16() is taken into account at the next sync point, and the square wave is still generated on the Modelica side between two calls. led0 lights up then dims gradually when the result is replayed with animation in OMEdit. Pins GP1-GP7, unused by this scenario, are left unconnected.

Components

TypeNameDefaultDescription
MCUmcuscriptPath = Resources/Scripts/MCU/pwm_led_fade.py
Modelica.Electrical.Analog.Basic.Groundground
Modelica.Electrical.Analog.Basic.Resistorr0limits the current of led0 (GP0)
MicroPythonMCU.Peripherals.LEDled0GP0: PWM at 1 kHz, varying duty cycle (fade in, fade out)