Making Furniture Interactive

September 24, 2007

[Dan D.W. Kang] Assignment Four

Filed under: Dong Woo Kang,Exercise 4: Four State Machines — dwkang @ 9:51 pm

*Description

My “state machine” for this assignment essentially uses the same system that I’ve created for assignment 3. This time, however, I re-wrote the code so that it has the four different states and transitions between them.

 

 

The transition of this system is simple. It goes from sleep – arousal – attract – reward, according to the proximity of the object to the sensor. The state can always step back to the previous state (for example from reward to attract) if you simply back away from the sensor.  If the person leaves the chair to the sideway, instead of gradually backing away from the chair, the system will enter the state of “sleep,” repeating the whole process from the start.

Here is how it works:

View A: http://www.youtube.com/watch?v=65ufWzWCrLc

View B: http://www.youtube.com/watch?v=FUAd_VZSnrA

* Configuration

There are seven different LEDs attached to the chair, making the system seem more complicated than it really is. All the red wires from the LEDs are connected to the ground pin and the green wires are connected to the digital pins on Arduino board.  The I/R sensor was used to dectect the distance from the chair to the object, and it is attached at the bottom of the back support of the chair.

 

*Code

int analogValue0 = 0;
int analogPin0 = 0;
int value = 0;
int red1 = 13;
int red2 = 4;
int yellow1 = 12;
int yellow2 = 5;
int green1 = 11;
int green2 = 6;
int blue = 7;

void setup()
{
pinMode(analogPin0, INPUT);
pinMode(red1, OUTPUT);
pinMode(red2, OUTPUT);
pinMode(yellow1, OUTPUT);
pinMode(yellow2, OUTPUT);
pinMode(green1, OUTPUT);
pinMode(green2, OUTPUT);
pinMode(blue, OUTPUT);
Serial.begin(9600);
}

void loop()
{

analogValue0 = analogRead(analogPin0);
Serial.print(”Raw Sensor value;”);
Serial.println(analogValue0);

//sleep
if (analogValue0 =150 && analogValue0 <225)
{
digitalWrite(red1, LOW);
digitalWrite(red2, LOW);
digitalWrite(yellow1,LOW);
digitalWrite(yellow2,LOW);
digitalWrite(blue,LOW);
for(value = 0 ; value =0; value-=5)
{
analogWrite(green1, value);
analogWrite(green2, value);
delay(20);
}

}
//attract

if(analogValue0 >= 225 && analogValue0 = 450)
{
digitalWrite(red1, LOW);
digitalWrite(red2, LOW);
digitalWrite(yellow1, LOW);
digitalWrite(yellow2, LOW);
digitalWrite(green1, LOW);
digitalWrite(green2, LOW);
digitalWrite(blue, LOW);

digitalWrite(red2, HIGH);
delay(50);
digitalWrite(red2, LOW);
digitalWrite(yellow2, HIGH);
delay(50);
digitalWrite(yellow2, LOW);
digitalWrite(green2, HIGH);
delay(50);
digitalWrite(green2, LOW);
digitalWrite(blue, HIGH);
delay(50);
digitalWrite(blue, LOW);
digitalWrite(green1, HIGH);
delay(50);
digitalWrite(green1, LOW);
digitalWrite(yellow1, HIGH);
delay(50);
digitalWrite(yellow1, LOW);
digitalWrite(red1, HIGH);
delay(50);
digitalWrite(red1, LOW);

digitalWrite(red1, HIGH);
delay(50);
digitalWrite(red1, LOW);
digitalWrite(yellow1, HIGH);
delay(50);
digitalWrite(yellow1, LOW);
digitalWrite(green1, HIGH);
delay(50);
digitalWrite(green1, LOW);
digitalWrite(blue, HIGH);
delay(50);
digitalWrite(blue, LOW);
digitalWrite(green2, HIGH);
delay(50);
digitalWrite(green2, LOW);
digitalWrite(yellow2, HIGH);
delay(50);
digitalWrite(yellow2, LOW);
digitalWrite(red2, HIGH);
delay(50);
digitalWrite(red2, LOW);

digitalWrite(red2, HIGH);
delay(50);
digitalWrite(red2, LOW);
digitalWrite(yellow2, HIGH);
delay(50);
digitalWrite(yellow2, LOW);
digitalWrite(green2, HIGH);
delay(50);
digitalWrite(green2, LOW);
digitalWrite(blue, HIGH);
delay(50);
digitalWrite(blue, LOW);
digitalWrite(green1, HIGH);
delay(50);
digitalWrite(green1, LOW);
digitalWrite(yellow1, HIGH);
delay(50);
digitalWrite(yellow1, LOW);
digitalWrite(red1, HIGH);
delay(50);
digitalWrite(red1, LOW);

digitalWrite(red1, HIGH);
delay(50);
digitalWrite(red1, LOW);
digitalWrite(yellow1, HIGH);
delay(50);
digitalWrite(yellow1, LOW);
digitalWrite(green1, HIGH);
delay(50);
digitalWrite(green1, LOW);
digitalWrite(blue, HIGH);
delay(50);
digitalWrite(blue, LOW);
digitalWrite(green2, HIGH);
delay(50);
digitalWrite(green2, LOW);
digitalWrite(yellow2, HIGH);
delay(50);
digitalWrite(yellow2, LOW);
digitalWrite(red2, HIGH);
delay(50);
digitalWrite(red2, LOW);

digitalWrite(red2, HIGH);
delay(50);
digitalWrite(red2, LOW);
digitalWrite(yellow2, HIGH);
delay(50);
digitalWrite(yellow2, LOW);
digitalWrite(green2, HIGH);
delay(50);
digitalWrite(green2, LOW);
digitalWrite(blue, HIGH);
delay(50);
digitalWrite(blue, LOW);
digitalWrite(green1, HIGH);
delay(50);
digitalWrite(green1, LOW);
digitalWrite(yellow1, HIGH);
delay(50);
digitalWrite(yellow1, LOW);
digitalWrite(red1, HIGH);
delay(50);
digitalWrite(red1, LOW);

digitalWrite(red1, HIGH);
delay(50);
digitalWrite(red1, LOW);
digitalWrite(yellow1, HIGH);
delay(50);
digitalWrite(yellow1, LOW);
digitalWrite(green1, HIGH);
delay(50);
digitalWrite(green1, LOW);
digitalWrite(blue, HIGH);
delay(50);
digitalWrite(blue, LOW);
digitalWrite(green2, HIGH);
delay(50);
digitalWrite(green2, LOW);
digitalWrite(yellow2, HIGH);
delay(50);
digitalWrite(yellow2, LOW);
digitalWrite(red2, HIGH);
delay(50);
digitalWrite(red2, LOW);

digitalWrite(red1, HIGH);
delay(500);
digitalWrite(green1, HIGH);
delay(500);
digitalWrite(yellow1, HIGH);
delay(500);
digitalWrite(blue, HIGH);
delay(500);
digitalWrite(green2, HIGH);
delay(500);
digitalWrite(yellow2, HIGH);
delay(500);
digitalWrite(red2, HIGH);
delay(500);

digitalWrite(red1, HIGH);
digitalWrite(yellow1, HIGH);
digitalWrite(green1, HIGH);
digitalWrite(blue, HIGH);
digitalWrite(green2, HIGH);
digitalWrite(yellow2, HIGH);
digitalWrite(red2, HIGH);
delay(2000);

}

}

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

Create a free website or blog at WordPress.com.

%d bloggers like this: