Description
Use multiple pots to effect 3 LEDs. My code uses one pot to control the blink rate of an LED. The second pot controls which LED is affected. The range of the potentiometer is divided into three sections and each one is assigned to one of the LEDs.
Components Used
3 Light Emitting Diodes (LED)
3 Resistors
2 Potentiometers
Arduino Code
/*
* one pot changes the blinking rate, the other determines which LED to affect
* 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 = 9; // select the pin for the LED 1
int led2Pin = 10; // select the pin for the LED 2
int led3Pin = 11; // select the pin for the LED 3
int chosenLED = 9; // initialize chosen LED to 9
void setup() {
pinMode(led1Pin, OUTPUT); // declare the led1Pin as an OUTPUT
pinMode(led2Pin, OUTPUT); // declare the led2Pin as an OUTPUT
pinMode(led3Pin, OUTPUT); // declare the led2Pin as an OUTPUT
}
void loop() {
pot1Val = analogRead(pot1Pin); // read the value from pot 1, between 0 - 1024, for blinking
pot2Val = analogRead(pot2Pin); // read the value from pot 2, between 0 - 1024, to select output LED
//the range of pot2 is divided into 3 sections, one for each LED
if (pot2Val > 682) chosenLED = 9; // LED 1 is in the range 683 - 1024
else if (pot2Val > 341) chosenLED = 10; // LED 2 is in the range 342 - 682
else chosenLED = 11; // LED 3 is in the range 0 - 341
analogWrite(chosenLED, 255); // light the selected LED
delay(pot1Val); // stop the program for some time, meaning, LED is on for this time
analogWrite(chosenLED, 0); // dim LED to completely dark (zero)
delay(pot1Val); // stop the program for some time, meaning, LED is OFF for this time
}
Item
Lab3