Pot Lab

Posted by Avery

Avery's picture

Description

Use two pots to control the blinking rate and dimming level of three LEDs. One pot controls blinking and the other controls color and dimming.

Components Used

  • 3x Light Emitting Diode (LED)
  • 3x Resistor
  • 2x Potentiometer

Arduino Code

/*
 * one pot dims and changes the color, the other pot changes the blinking rate
 * modification of the following
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 */
int pot1Pin = 1;   // select the input pin for the potentiometer 1
int pot2Pin = 2;   // 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;
int led3Pin = 11;  // select the pin for the LED 2

void setup() {
   pinMode(led1Pin, OUTPUT);  // declare the led1Pin as an OUTPUT
   pinMode(led2Pin, OUTPUT);  // declare the led2Pin as an OUTPUT
   pinMode(led3Pin, OUTPUT);
}
void loop() {
   pot1Val = analogRead(pot1Pin);   // read the value from pot 1, between 0 - 1024, for dimming and color changing
   pot2Val = analogRead(pot2Pin);   // read the value from pot 2, between 0 - 1024, for blinking
   if (pot1Val >= 0 && pot1Val <= 341) {
    analogWrite(led1Pin, pot1Val*3);
   }
   if (pot1Val > 341 && pot1Val < 682) {
   analogWrite(led2Pin, pot1Val);
   }
   if (pot1Val >= 682) {
    analogWrite(led3Pin, pot1Val/3);
   }
   
   delay(pot2Val);                  // stop the program for some time, meaning, LED is on for this time
   analogWrite(led1Pin, 0);
   analogWrite(led2Pin, 0);         // dim LED to completely dark (zero)
   analogWrite(led3Pin, 0);
   delay(pot2Val);                  // stop the program for some time, meaning, LED is OFF for this time
}

Video

http://www.youtube.com/watch?v=O9BPZWs_eGg

0
Your rating: None
Tags: