Blink 'n' fade control

Submitted by MarieSpliid on Mon, 02/18/2013 - 17:13
MarieSpliid's picture

 

Description

In this lab assignment I have created a circut that lets you control three LED's with two potentiometers. One potentiometer controls the brightness of all three LED's and the other potentiometer controls the blinking speed of all three LED's.

Components

  • 3 x LED Lights (red, green blue)

  • 3 x Resistor (220 ohm)

  • Breadboard

  • Arduino

  • cables

  • USB Cable

  • 2 x potentiometers
 
Challenges
In order to make it work, I started out with the code snippet from "SinglePot_ControlsBrightness" and then added two extra LED's and then an extra potentiometer for blink control. To be able to see at what rage the potentiometers were working, I used the Serial.print to make serial monitor print the maximum value of the potentiometers. Knowing that the LED's work with 0-255 I divided the maximum potentiometer value (1023) with 256, which is 4, and therefore the value that is read from the potentiometer is divided by 4.
 

 
Code
 
/* 
One potentiometer controls the brightnes of 3 LEDs. Another potentiometer controls the blinking speed of the three LEDs.
 */
int potBright = A1;   //input pin for the brightness control potentiometer
int potBlink = A0;    //input pin for the blink control potentiometer
int ledRed = 5;    // pin for red LED
int ledGreen = 9;  // pin for green LED
int ledBlue = 10;  // pin for blue LED
int valBright = 0; // variable to store the value coming from the brightness control potentiometer
int valBlink = 0;  // variable to store the value coming from the blink control potentiometer
void setup() {
  Serial.begin(9600);
}
void loop() {
  valBright = analogRead(potBright); // read the value from the sensor controlling the brightness (between 0 - 1023).
  Serial.print("Brightness value: ");
  Serial.println(valBright);
  valBlink = analogRead(potBlink); // read the value from the sensor controlling the blinking (between 0 - 1023).
  Serial.print("Blink value: ");
  Serial.println(valBlink);
  analogWrite(ledRed, valBright/4); // analogWrite can be between 0-255 and the  potentiometer runs from 0-1023. Therefore the pot value is divided by 4.
  analogWrite(ledGreen, valBright/4);
  analogWrite(ledBlue, valBright/4);
  delay(valBlink/4);               // wait in current potentiometer value of time
  digitalWrite(ledRed, LOW);    // turn the LEDs off by making the voltage LOW
  digitalWrite(ledGreen, LOW);
  digitalWrite(ledBlue, LOW);
  delay(valBlink/4);               // wait in current potentiometer value of time
  
 
photo (1).JPG
0
Your rating: None
Drupal theme by Kiwi Themes.