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

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,…

Contents