Making Furniture Interactive

September 19, 2007

Kipum Lee’s Exercise 3

Filed under: Exercise 3: Four States,Kipum Lee — Kip @ 1:11 am

Playing around with the photosensor, I made the sensitivity change the state of an orange LED from “sleep” to “arousal” by simply changing from “off” to a “fading in.” When more light was obstructed from the sensor, this triggered a blue LED (on the straw) to start blinking.

Another state I played around with is just LED’s lighting up in consecutive order. I’m not sure as to how I’m going to tie it into the other 3 states, but I’m just happy that they’re working for now.

CODE:
//Kipum Lee
//Exercise 3

int value = 0; // variable to keep the actual value
int ledpin = 9; // light connected to digital pin 9

int state = 1; // 1=sleep, 2=attract, 3=arousal, 4=reward

int ledMeter1 = 7;
int ledMeter2 = 5;
int ledMeter3 = 4;
int ledMeter4 = 3;

//for state 4
int potPin = 2; // select the input pin for the potentiometer
int val = 0; // variable to store the value coming from the sensor
int onoff = 0; // 0=fading off, 1=fading on, 2=blink
int state4Pin = 10;

void setup()
{
pinMode(ledpin, OUTPUT); // turns on LED in pin #9 PWM
pinMode(ledMeter1, OUTPUT); // turns on LED in pin #7
pinMode(ledMeter2, OUTPUT); // turns on LED in pin #5
pinMode(ledMeter3, OUTPUT); // turns on LED in pin #4
pinMode(ledMeter4, OUTPUT); // turns on LED in pin #3
pinMode(state4Pin, OUTPUT); // turns on LED in pin #10 PWM
}

void loop()
{
state = 4; // manually turning on state 4

if(state == 1) // if state 1 …
{
sleep(); // state 1 = sleep
}
else if (state == 2)
{
attract(); // state 2 = attract
}
else if (state == 3)
{
arouse(); // state 3 = arouse
}
else if (state == 4)
{
reward(); // state 4 = reward
}
}

//state: sleep = 1
void sleep()
{
for(value = 0 ; value =0; value-=5) // fade out (from max to min)
{
analogWrite(ledpin, value);
delay(30);
}
}

//state: attract = 2 // blinking
void attract()
{
for(int i=0; i< 3;i++)
{
analogWrite(ledpin, 255);
delay(300);
analogWrite(ledpin, 0);
delay(300);
}

}

//state: arouse = 3
void arouse()
{
digitalWrite(ledMeter1, HIGH);
delay(300);
digitalWrite(ledMeter2, HIGH);
delay(300);
digitalWrite(ledMeter3, HIGH);
delay(300);
digitalWrite(ledMeter4, HIGH);
delay(600);

digitalWrite(ledMeter4, LOW);
delay(300);
digitalWrite(ledMeter3, LOW);
delay(300);
digitalWrite(ledMeter2, LOW);
delay(300);
digitalWrite(ledMeter1, LOW);
delay(600);
}

//state: reward = 4
void reward() {
val = analogRead(potPin); // read the value from the sensor
if(val < 90 && onoff == 0) { //turns on LED when light is off. change to make it turn on with light
for(value = 0 ; value = 100 && onoff == 1) { // “&&” means all these have to be true
for(value = 255; value >=0; value-=15) // fade out (from max to min in multiples of 15)
{
analogWrite(ledpin, value);
delay(20); // waits for 20 milli seconds to see the dimming effect
}
onoff = 0; // 0 = turns off LED
}
else if (val < 30 && onoff == 1) {
for(int i=0; i< 3;i++)
{
analogWrite(state4Pin, 255);
delay(300);
analogWrite(state4Pin, 0);
delay(300);
}
onoff = 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: