Lab 3

albert_tjoeng's picture

 

/**************************************************************************************
Albert Tjoeng - Lab3, Potientiometer
ATJ: 09-14-2011
 
description:  use two pots to ontrol the LED. I use one pot to control the brightness,
              the other pot is to control how fast it blink. the blinking is bounded 
              from 0 second delay to 2 second delay.
              
***************************************************************************************/
 
int pwmPins[] = {11, 6, 5};
int potPinBright = 5;
int potPinBlink = 4;
int valBright = 0 ;
int valBlink = 0 ;
void setup()                    // run once, when the sketch starts
{
  for (int i = 0; i<=2; i++){
    pinMode (pwmPins[i], OUTPUT);
  }  
}
 
void loop()                     // run over and over again
{
  valBright = analogRead(potPinBright);
  valBright = map(valBright, 1, 1022, 0, 255);
  
  valBlink = analogRead(potPinBlink);
  valBlink = map(valBlink, 1, 1022, 1, 2000);
  
  for (int i = 0; i<=2; i++){
    analogWrite(pwmPins[i], valBright);
  };
  
  if (valBlink > 5){ // if the blink is too fast, just keep it on.
    delay(valBlink);
    
    for (int i = 0; i<=2; i++){
      analogWrite(pwmPins[i], LOW);
    };
    delay(valBlink);
  }
}
photo.JPG
0
Your rating: None