Making Furniture Interactive

September 4, 2007

Kipum Lee’s Straw Lights

Filed under: Exercise 0: Make A Lamp,Kipum Lee — Kip @ 11:23 pm

First, I started off by playing with the arduino microprocessor and then manipulating some basic tutorial code.
Although I had a working code that slightly manipulated the tutorial code, today’s lesson from Mark was very helpful in understanding (at least vaguely) each line of the code.

Playing around with the delay as well as the three deltas, I got a red light that flickers very fast, a blue that pulsates similar to the heartbeat of someone who has just exercised, and a green that is slower, with the fading ins and outs a bit more noticable.

Click Image to Enlarge:
Making Just the Blue LED Work

This is a shot of all three LED’s working

Arduino & Breadboard

Code:
// Fading 3 LED’s
// 3 PARTS FOR EVERY ARDUINO PROGRAM: DECLARATION, SETUP, & LOOP
// a FADING LED program that uses a count-down timer to gradually dim and brigten an LED.
// modified MDG

// 4 variables
int timer_red = 255;
int timer_blue = 255;
int timer_green = 255;

int delta_red = 20; // Three deltas (amount to dim or brighten).
int delta_blue = 6;
int delta_green = 2;

int brightness_red = 0;
int brightness_blue = 0;
int brightness_green = 0;

int redledpin = 9; // LED’s connect to the three PWM pins on Arduino.
int blueledpin = 10;
int greenledpin = 11;

void setup()
{
//nothing for setup
}

void loop()
{
analogWrite (redledpin, brightness_red);
analogWrite (blueledpin, brightness_blue);
analogWrite (greenledpin, brightness_green);

delay (5);

brightness_red = brightness_red + delta_red;
brightness_blue = brightness_blue + delta_blue;
brightness_green = brightness_green + delta_green;

timer_red = timer_red – 1;
timer_blue = timer_blue – 1;
timer_green = timer_green – 1;

if (timer_red <= 0)
{timer_red = 255;
delta_red = delta_red * -1;
}

if (timer_blue <= 0)
{timer_blue = 255;
delta_blue = delta_blue * -1;
}

if (timer_green <= 0)
{timer_green = 255;
delta_green = delta_green * -1;
}

}

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: