From the course: Learning Arduino: Interfacing with Analog Devices
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Coding to control the LED with a potentiometer - Arduino Tutorial
From the course: Learning Arduino: Interfacing with Analog Devices
Coding to control the LED with a potentiometer
- [Instructor] All right, so in this example, we are going to use the potentiometer input to control the brightness of the LED. So the very first thing we are going to do is we are going to initialize the connection, the pins that we connected to the potentiometer and the LED. So int, and then I'm going to name it as analogPin, and this is the input from the potentiometer, which is connected to A0. And then, the pin that was connected to LED, which is pin nine, which I'm going to name it ledPin equals nine, which is the digital pin nine. In the next step, I'm going to initialize the variable that I'm going to use to store the value that's coming from the sensor. So input, I'm going to name it inputValue, and then initialize the variable that I'm going to store the output mapped values, and then input outputValue, and then I'll initialize it with zero to start with. Now in the void setup, we are going to initialize the pinMode for the two pins that we have for LED. Pin, it's in OUTPUT,…
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)
-
-
-