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 - Arduino Tutorial
From the course: Learning Arduino: Interfacing with Analog Devices
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
How Arduino generates analog output1m 4s
-
(Locked)
Understanding pulse-width modulation (PWM)2m 8s
-
(Locked)
Understanding the analogWrite function with PWM1m 19s
-
(Locked)
Wire up an LED1m 5s
-
(Locked)
Write code to use PWM with the LED1m 56s
-
(Locked)
Understanding the map() function1m 45s
-
(Locked)
Wiring a potentiometer to control LED1m 13s
-
(Locked)
Coding to control the LED with a potentiometer3m 42s
-
(Locked)
-
-
-