From the course: Learning Arduino: Interfacing with Analog Devices

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Write code to use PWM with the LED

Write code to use PWM with the LED - Arduino Tutorial

From the course: Learning Arduino: Interfacing with Analog Devices

Start my 1-month free trial

Write code to use PWM with the LED

- [Instructor] So for the coding for this LED, I'm going to use one of the built-in examples within Arduino Library. So I'm going to go ahead to file, examples, analog, and then I'll select fading. So, I'll go ahead here, and then I'll simply little bit about the code. So on line 19 here, we are connecting the LED pin to a number nine, which we did with a wiring. In the void loop. You can see there are two for loops. The first for loop, that starts from zero, all the way to 255. Because we're sending values from zero to 255. And then the increment is five units. In line 29, you see that the analog write, because this is the command that we use when we're sending pulse with modulation. We need to specify the pin. This case is LED pin that we have. And then the value that's being changing is the fade value from the for loop. And then this for loop is increasing from zero all the way 255, so the light will increase in brightness. The second for loop from line 35 all the way to line 39…

Contents