Lab 3: Red/Blue blending with potentiometer

Submitted by alexis.taylor on Mon, 02/18/2013 - 19:04

Description

For this lab, I first extended the circuit to include one potentiometer to control LED blinking speed. I then extended the circuit to include another potentiometer, and tried out code to use one pot to control blinking and one to control brightness. Since I only have two pots, I decided to write a code that uses one pot to control blinking, and the other to map an LED at full brightness each end of the range to blend two colors - when one LED is at full, the other is at zero and vice-versa.

Components Used

1 arduino uno R3 (5V)

3 220 Ω resistor

2 LED (red, blue)

8 wires (1 red, 2 yellow, 2 green, 3 orange)

2 potentiometers
1 USB cable

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 = 9;   // select the pin for the LED 1
int led2Pin = 11;  // select the pin for the LED 2
int led1Val;       // maps LED 1 brightness to one end of pot range
int led2Val;      // maps LED 2 brightness to inverse end of pot range
 
void setup() {
   pinMode(led1Pin, OUTPUT);  // declare the led1Pin as an OUTPUT
   pinMode(led2Pin, OUTPUT);  // declare the led2Pin as an OUTPUT
}
void loop() {
   pot1Val = analogRead(pot1Pin)/4; //converts pot max range 1024 to LED max range 255
   led1Val = pot1Val; //sets LED 1 to pot value
   led2Val = 255 - pot1Val; // sets LED 2 to inverse value
   analogWrite(led1Pin, led1Val);
   analogWrite(led2Pin, led2Val);
   
   pot2Val = analogRead(pot2Pin);   // read the value from pot 2, between 0 - 1024, for blinking
   delay(pot2Val);                  // stop the program for some time, meaning, LED is on for this time
   analogWrite(led2Pin, 0);         // dim LED to completely dark (zero) 
   analogWrite(led1Pin, 0);         // dim LED to completely dark (zero) 
   delay(pot2Val);                  // stop the program for some time, meaning, LED is OFF for this time
}
 
lab3.jpg
0
Your rating: None
Drupal theme by Kiwi Themes.