Jenton Lee - Lab 3 Submission

Submitted by Jenton on Fri, 02/15/2013 - 13:37

Items Used:

  • 2 Potentiometers
  • many cables
  • 3 led lights
  • arduino board
  • breadboard

Description:

I used two potentiometers. One pot controlled the blinking rate as specified in the lab example, while the other pot controlled the brightness AND the sequence that the LEDs were turned on in. I modified my code so that if the brightness pot value was set from 0 to 342, only the green LED would turn on. From 342 to 683, the green and the red LED would turn on. And then from 683 up to 1024, all three LED lights would turn on. The level of brightness of each LED was still determined by the Pot value.

My Code:

 

/*
 * one pot dims and determines the sequence the LEDs turn on in, the other pot changes the blinking rate
 */
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 ledGreenPin = 9;   // select the pin for the Green LED
int ledRedPin = 10;  // select the pin for the Red LED
int ledBluePin = 11;  // select the pin for the Blue LED
int ColorFlip = 0;
 
void setup() {
   pinMode(ledGreenPin, OUTPUT);  // declare the led1Pin as an OUTPUT
   pinMode(ledRedPin, OUTPUT);  // declare the led2Pin as an OUTPUT
   pinMode(ledBluePin, OUTPUT);  // declare the led2Pin as an OUTPUT   
   Serial.begin(9600);
   analogWrite(ledRedPin, 0);
     analogWrite(ledGreenPin, 0);
   analogWrite(ledBluePin, 0);         // dim LED to completely dark (zero)    
}
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
   Serial.println(pot1Val);
   Serial.println(pot2Val);   
   if (pot1Val <= 342 && pot1Val >=0) { //if pot 1 is between 0-342, only the green LED is turned on
     analogWrite(ledGreenPin, pot1Val/4);      
     analogWrite(ledRedPin, 0);
     analogWrite(ledBluePin, 0);      
     delay(pot2Val);                       
     analogWrite(ledGreenPin, 0);         // dim LED to completely dark (zero)
     delay(pot2Val);  
     analogWrite(ledGreenPin, pot1Val/4);
   }
   else if (pot1Val >= 342 && pot1Val < 683) { //if pot 1 is between 342 and 683, the green and the red LED turns on
      analogWrite(ledRedPin, pot1Val/4);
      analogWrite(ledGreenPin, pot1Val/4); 
      analogWrite(ledBluePin, 0);       
      delay(pot2Val);
      analogWrite(ledRedPin, 0);      
      analogWrite(ledGreenPin, 0); 
      analogWrite(ledGreenPin, 0);         // dim LED to completely dark (zero)
      delay(pot2Val);  
      analogWrite(ledRedPin, pot1Val/4);
      analogWrite(ledGreenPin, pot1Val/4);  
      analogWrite(ledBluePin, 0);  
   }
   else if (pot1Val >= 683) { //if pot 1 is greater than 683, then the blue light will turn on too
      analogWrite(ledRedPin, pot1Val/4); 
      analogWrite(ledBluePin, pot1Val/4);
      analogWrite(ledGreenPin, pot1Val/4);        
      delay(pot2Val);
      analogWrite(ledRedPin, 0); 
      analogWrite(ledBluePin, 0);
      analogWrite(ledGreenPin, 0);
      delay(pot2Val);      
      analogWrite(ledRedPin, pot1Val/4); 
      analogWrite(ledBluePin, pot1Val/4);
      analogWrite(ledGreenPin, pot1Val/4);              
   }
 
}
My Potentiometer Setup
0
Your rating: None
Drupal theme by Kiwi Themes.