Making Furniture Interactive

September 4, 2007

Imran’s Exercise 0

Filed under: Exercise 0: Make A Lamp,Imran Sobh,Students — imranixd @ 2:00 pm

This exercise was a good introduction to get at the basics of how to make furniture “interactive.” I started out just trying to get three lights to light up using the default loop example. This involved some trial and error to simply get the correct components in the circuit. I’m still unsure what kind of resister is appropriate and if it is overloading the LED or not.


The next challenge was to apply them to something physical. I bent the wires and pins going into the LED to make them hook into each other. This made it so that they would be touching all the time. There’s probably a better way to do this.


I decided to change the default programming in the example to get the LEDs to fade and do other behavior. After some frustration, I found out that fading only works with the slots on the board that have PWM written next to it. Apparently these are analog slots.


The final program fades in each light, then flickers out of synch with an LED on the bread board. Over time, the delay between flickers gets shorter until it can’t get any shorter, then gets longer and repeats this forever.

Code:

int value = 0; // variable to keep the actual value
int ledpin = 3; // light connected to digital pin 9
int ledpin2 = 5;
int ledpin3 = 6;
int ledpin4 = 9;
int tweenDelay = 500;
boolean goingDown = true;

void setup()
{
// nothing for setup
}

void loop()
{

if(tweenDelay==0)
{
goingDown = false;
}
if (tweenDelay==500)
{
goingDown = true;
}

if(goingDown)
{
tweenDelay-=100;
}

if(!goingDown)
{
tweenDelay+=100;
}

for(value = 0 ; value <= 255; value+=20) // fade in (from min to max)
{
analogWrite(ledpin, value); // sets the value (range from 0 to 255)
delay(30); // waits for 30 milli seconds to see the dimming effect
}
for(value = 0 ; value <= 255; value+=20) // fade in (from min to max)
{
analogWrite(ledpin2, value);
delay(30);
}
for(value = 0 ; value <= 255; value+=20) // fade in (from min to max)
{
analogWrite(ledpin3, value);
delay(30);
}

for(int i=0; i<=3; i++)
{
allOff();
for(value = 0 ; value <= 5; value+=1)
{
analogWrite(ledpin4, value);
}
delay(tweenDelay);

allOn();
for(value = 4; value >=0; value-=1)
{
analogWrite(ledpin4, value);
}
delay(tweenDelay);

}

for(value = 255; value >=0; value-=5) // fade out (from max to min)
{
analogWrite(ledpin, value); // sets the value (range from 0 to 255) // waits for 30 milli seconds to see the dimming effect
analogWrite(ledpin2, value);
analogWrite(ledpin3, value);

}
delay(300);

}

void allOff()
{
analogWrite(ledpin, 0);
analogWrite(ledpin2, 0);
analogWrite(ledpin3, 0);

}

void allOn()
{
analogWrite(ledpin, 255);
analogWrite(ledpin2, 255);
analogWrite(ledpin3, 255);

}

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: