PWM LED Blink

Power Control

To create a Pulse Width Modulated (PWM) signal you need to determine the time length of a full duty cycle (time power will be applied). Then the output will be toggled on then off for a certain percentage of the duty cycle thus controlling the amount of power applied. The % time it is on vs the total time of the duty cycle will be the Pulse Width.
In this case to get the desired effect of dimming an LED, the power going through the LED will be controlled in the Duty cycle (30ms was chosen). The Code in the Tinker Cad simulation will go through 2 loops the first which starts with the LED on for the full 30ms Then decrements the on time by 1ms until it is off for the entire 30 ms. The Second Loop Then increments from 1ms – 29ms then after the code starts the loops again ( 30 -> 0 -> 1 -> 29)

Tinker Cad Simulation

Code to make LED Blink with PWM