# lab assignment_03

Submitted by njohn on Tue, 02/19/2013 - 23:18
##### //description

Following the successful construction of the 3 potentiometer circuit, I wanted to expand the exercise by using the input from the pots to affect multiple variables at the same time.  I decided that I would work with brightness/hue of the 3 leds, as well as a high/low "blink" delay.  I set up a very simple mathematical relationship between the input from the pots and the timing, so that as the value of the input increased, the delay decreased.

When all the pots are at max, there is no perceptible delay.  What caused problems was when the pots registered input values that approached zero.  I first tried to deal with this via an "if" statement in the code, which produced interesting results.  Ultimately, I realized the pots were grounding out, and inserted a 330 ohm resistor in line with all 3 pots, which solved the problem.

##### //materials used

1 x red LED

1 x green LED

1 x blue LED

1 x arduino uno

3 x potentiometers

4 x 330 ohm resistors

1 x ping pong ball

##### //code
int pot1 = 0;   // select the input pin for potentiometer 1
int pot2 = 1;// select the input pin for potentiometer 2
int pot3 = 2;// select the input pin for potentiometer 3

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 pot3Val = 0;   // variable to store the value coming from pot 2

int red   = 9;   // Red LED,   connected to digital pin 9
int green = 10;  // Green LED, connected to digital pin 10
int blue  = 11;  // Blue LED,  connected to digital pin 11

void setup() {
pinMode(red,   OUTPUT);   // sets the pins as output
pinMode(green, OUTPUT);
pinMode(blue,  OUTPUT);
Serial.begin(9600);
analogWrite(red,   255);   // set them all to max brightness to signal initiation
analogWrite(green, 255);
analogWrite(blue,  255);
Serial.println("enter letters corresponding to the led colors (e.g 'r', 'g')  for each occurence of a letter, the brightness of that led will increase :");
}

void loop() {

analogWrite(red, pot1Val/4);   // dim red LED to value from pot1
analogWrite(green, pot2Val/4);
analogWrite(blue, pot3Val/4);

if( pot1Val == 0){
delay(5000);
}

else if( pot1Val>0){
delay(3000/pot1Val);
}

if( pot2Val == 0){
delay(5000);
}

else if( pot2Val>0){
delay(3000/pot2Val);
}

if( pot3Val == 0){
delay(5000);
}

else if( pot3Val>0){
delay(3000/pot3Val);
}

analogWrite(red, 0);   // dim red LED to value from pot1
analogWrite(green, 0);
analogWrite(blue, 0);

delay(3000/pot1Val);
delay(3000/pot2Val);
delay(3000/pot3Val);
}

Drupal theme by Kiwi Themes.