Making Furniture Interactive

September 19, 2007

Blinkidy

Filed under: Exercise 3: Four States,Jamin Hegeman — Jamin Hegeman @ 12:25 am

I made three LEDs glow or blink given different light conditions. Not sure if it completes the assignment, but I was happy to get it working. Sleep is nothing happening. Attract is when the white light glows when it starts to sense darkness. Arousal occurs as you get closer: the green LED blinks. The reward is touching the photocell, which illuminates the red LED.


int potPin = 2;    // select the input pin for the potentiometer
int ledPin = 3;   // select the pin for the LED
int ledPin2 = 10;
int ledPin3 = 6;
int inPin = 7;   // choose the input pin (for a pushbutton)

int val = 0;
int buttonVal = 0;       // variable to store the value coming from the sensor
int value = 0;     // variable to keep the actual value
int state = 0;
int state2 = 0;
int sensitivity = 80;
int sensitivity2 = 12;
int sensitivity3 = 8;

void setup() {
pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
Serial.begin(9600);
fadeIn(ledPin3);
}

void loop() {
val = analogRead(potPin);    // read the value from the sensor
if(val < sensitivity &amp;&amp; state == 0) {
fadeIn(ledPin);
state = 1;
}
else if(val >= sensitivity &amp;&amp; state == 1) {
fadeOut(ledPin);
state = 0;
}
if(val < sensitivity2 &amp;&amp; state2 == 0 &amp;&amp; state == 1) {
fadeIn(ledPin2);
state2 = 1;
}
else if(val >= sensitivity2 &amp;&amp; state2 == 1 &amp;&amp; state == 0) {
fadeOut(ledPin2);
state2 = 0;
}
if(val < sensitivity3 &amp;&amp; state == 0) {
fadeIn(ledPin3);
}
else if(val >= sensitivity3 &amp;&amp; state == 1) {
fadeOut(ledPin3);
}

Serial.println(val);
}

void fadeIn(int pin) {
//Serial.println(pin);
for(value = 0 ; value <= 255; value+=5) // fade in (from min to max)
{
analogWrite(pin, value);           // sets the value (range from 0 to 255)
delay(10);                            // waits for 30 milli seconds to see the dimming effect
}
}

void fadeOut(int pin) {
//Serial.println(pin);
for(value = 255; value >=0; value-=5)   // fade out (from max to min)
{
analogWrite(pin, value);
delay(10);
}
}
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: