3LED2POTS

Submitted by sebarness on Mon, 02/18/2013 - 15:23

 

Materials
-two Pots
-3 LED's(RGB)
-Arduino
-Breadboard
-wires
-resistors 
 
DESCRIPTION 
I used two pots to control my 3 LED's. The first pot controls the brightness of the LED's. The second pot controls the rate of blinking. When you turn the first pot onto full brightness it looks like you are turning the LED's off one by one. If you turn the brightness off then it looks like each LED lights up and then goes off down the row. 
 
CODE
/*
 * one pot fades one led
 * modified version of AnalogInput
 * by DojoDave <http://www.0j0.org>
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 */
int potPin = 2;   // this pot will control the brightness
int potpin = 3;    //this one will control the blinking LED's
int redPin = 9;// select the pin for the LED
int greenPin = 10;
int bluePin = 11;
int redValue = 0;
int greenValue = 0;
int blueValue = 0;  // variable to store the value coming from the sensor
int val;
 
void setup() {
  Serial.begin(9600);
pinMode(redPin, OUTPUT); 
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
 
void loop() {
  redValue = analogRead(potPin);
  greenValue = analogRead(potPin);
  blueValue = analogRead(potPin);  // read the value from the sensor, between 0 - 1024
  Serial.println(redValue);
  Serial.println(greenValue);
  Serial.println(blueValue);
  analogWrite(redPin, redValue/4); // analogWrite can be between 0-255
  analogWrite(greenPin, greenValue/4);
  analogWrite(bluePin, blueValue/4);
  
   val = analogRead(potpin);   // reads the value of the potentiometer (value between 0 and 1023) 
  Serial.println(val);
  val = map(val, 0, 1023, 500, 5);    // 
  digitalWrite(redPin, HIGH);
  delay(val);                           //  
  digitalWrite(redPin, LOW);
  delay(val);
   digitalWrite(greenPin, HIGH);
  delay(val);                           //  
  digitalWrite(greenPin, LOW);
  delay(val);
   digitalWrite(bluePin, HIGH);
  delay(val);                           // 
  digitalWrite(bluePin, LOW);
  delay(val);
  
 
}
0
Your rating: None
Drupal theme by Kiwi Themes.