Lab #3: Blink & Fade with 2 potentiometers

Submitted by christineschantz on Tue, 02/19/2013 - 16:28

Description 

In this assignment I use two analog potentiometers to control my LEDs (R/G/B). One of the potentiometers controls the blinking speed of the LEDs, while the other regulate the fading. The connected potentiometers controls the all three LEDs at the same time. 

 

Components

 

2 x Potentiometers 

3 x LED Lights (R, G, B) 

3 x resister

USB cable

Breadboard

Arduino

1 x elastic

Leads

 
Challenges 
I took me a while to realize that i did not need to do 'digitalWrite (HIGH)' for the potentiometer that controlled the blink - this value (HIGH) was already turned on. 
 

Code

 

/*
 * one pot fades one led
 * modified version of AnalogInput
 * by DojoDave <http://www.0j0.org>
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 */
int potBrightness = A0; // select the input pin for the potentiometer (controls brightness)
int potBlink = A1; // select the input pin for the potentiometer (controls blink)
int ledBlue = 11;  // set the pin for the Blue LED
int ledGreen = 10; // set the pin for the Green LEd
int ledRed = 9; // set the pin for the Red LED
int value = 0; // variable to store the value coming from the sensor
 
 
void setup() {
  Serial.begin(9600);
}
void loop() {
  value = analogRead(potBrightness);    // read the value from the sensor, between 0 - 1024
  Serial.println(potBrightness);
  analogWrite(ledBlue, value/4); // analogWrite can be between 0-255
  analogWrite(ledGreen, value/4); // analogWrite can be between 0-255 // turns on, do not need to declare HIGH
  analogWrite(ledRed, value/4); // analogWrite can be between 0-255 // turns on, do not need to declare HIGH
   
  value = analogRead(potBlink);    // read the value from the sensor
  delay(value);                  // stop the program for some time
  digitalWrite(ledBlue, LOW);   // turn the ledBlue off 
  digitalWrite(ledGreen, LOW); //turn the ledGreen off
  digitalWrite(ledRed, LOW); //turn the ledRed off
  delay(value);                  // stop the program for some time
}
photo.JPG
photo2.JPG
0
Your rating: None
Drupal theme by Kiwi Themes.