DESCRIPTION
In this lab, we explored how potentiometers (pots) can be used as analog input to control LED traits, such as dimness or blink speed. We began by soldering three wires to our pots and setting up our breadboard to connect to one LED light. The two pots (with newly soldered wires) are connected to the analog input to control different aspects of the LED light; in this case the dimness and the blink speed of the single LED. One purpose is to understand how analog inputs work and the wide spectrum of inputs that we can work with.
COMPONENTS USED
1 - Arduino Uno
1 - Breadboard
1 - Green LED
1 - USB Cable
1 - 220 Ohm Resistor
2 - Potentiometers
7 - Wires
CODE
/*
* one pot dims, the other pot changes the blinking rate
* modification of the following
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int pot1Pin = 0; // select the input pin for the potentiometer 1
int pot2Pin = 1; // select the input pin for the potentiometer 2
int pot1Val = 0; // variable to store the value coming from pot 1
int pot2Val = 0; // variable to store the value coming from pot 2
int led1Pin = 11; // select the pin for the LED 1
void setup() {
pinMode(led1Pin, OUTPUT); // declare the led1Pin as an OUTPUT
}
void loop() {
pot1Val = analogRead(pot1Pin); // read the value from pot 1, between 0 - 1024, for dimming
pot2Val = analogRead(pot2Pin); // read the value from pot 2, between 0 - 1024, for blinking
analogWrite(led1Pin, pot1Val/4); // dim LED to value from pot1
delay(pot2Val); // stop the program for some time, meaning, LED is on for this time
analogWrite(led1Pin, 0); // dim LED to completely dark (zero)
delay(pot2Val); // stop the program for some time, meaning, LED is OFF for this time
}
- Login to post comments