Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!


Three LED lab

Project Members: 
Igor P

Three LED Fade

Description

Did the standard cirucit, see 

 

lab2-led-small

lab2-led-small

For the serial control, I downloaded the program and, to my surprise, found that I had to uncomment just one line. Tada!! 

As for a diffuser, I was using Johnson and Johnson athletic tape under foam - it's the foamy tape you put under athletic tape to not rip out hair. It's folded over several times and because it's thin foamy material it provides an interesting effect. However, now that I'm editing this lab 3 weeks later, I think the effect isn't so cool. Instead, I used a glass crystal with a laser etched box surface. The organgish laser etching reflects the light into the crystal wich disperses it more than diffuses. Because the effect was subtle, I took pictures in the closet.

 

led-diffuse

led-diffuse

Because my simple camera can't take pictures in the dark, it's a bit less exiciting with the even weak flash. I also noticed the diffusion works pretty well on the white closet ceiling 3 feet up:

diffuse-on-ceiling

diffuse-on-ceiling

Materials

3 LEDs, 3 r/r/b/g resistors, a laser etched plastic box cover, a glass crystal.

Arduino Code

// Output
int redPin   = 6;   // Red LED,   connected to digital pin 9
int greenPin = 3;  // Green LED, connected to digital pin 10
int bluePin  = 5;  // Blue LED,  connected to digital pin 11

// Program variables
int redVal   = 255; // Variables to store the values to send to the pins
int greenVal = 1;   // Initial values are Red full, Green and Blue off
int blueVal  = 1;

int i = 0;     // Loop counter   
int wait = 10; // 50ms (.05 second) delay; shorten for faster fades
int DEBUG = 1; // DEBUG counter; if set to 1, will write values back via serial

void setup()
{
  pinMode(redPin,   OUTPUT);   // sets the pins as output
  pinMode(greenPin, OUTPUT);  
  pinMode(bluePin,  OUTPUT);
  if (DEBUG) {           // If we want to see the pin values for debugging...
    Serial.begin(9600);  // ...set up the serial ouput on 0004 style
  }
}

// Main program
void loop()
{
  i += 1;      // Increment counter
  if (i < 255) // First phase of fades
  {
    redVal   -= 1; // Red down
    greenVal += 1; // Green up
    blueVal   = 1; // Blue low
  }
  else if (i < 509) // Second phase of fades
  {
    redVal    = 1; // Red low
    greenVal -= 1; // Green down
    blueVal  += 1; // Blue up
  }
  else if (i < 763) // Third phase of fades
  {
    redVal  += 1; // Red up
    greenVal = 1; // Green low
    blueVal -= 1; // Blue down
  }
  else // Re-set the counter, and start the fades again
  {
    i = 1;
  } 

  analogWrite(redPin,   redVal);   // Write current values to LED pins
  analogWrite(greenPin, greenVal);
  analogWrite(bluePin,  blueVal); 
  delay(wait); // Pause for 'wait' milliseconds before resuming the loop
}


Comments

GSI Comments

The concept for the diffuser sounds cool -- I wish there was a picture of it on this page! If you have a chance, could you please upload one so that we can compare it to the picture you have of the three LEDs by themselves?

It is nice when the code just works. :) If you want to learn more about Arduino programming, one possibility is to try and write the code first without looking at the example code, and then using the example code to help if you get stuck.


Powered by Drupal - Design by Artinet