Making Furniture Interactive

September 12, 2007

Lampiethingy (iLamp? nah)

I tried to combine two vaguely useful functions into one ugly black project box for this assignment. I plan to market it to paranoid children. Basically, it’s a nightlight that also counts how many times an intruder parent walks past to steal your cookies. Lampy Thing

Schematics, Code, and more camera love after the breakSchematic
Innards
//ir lampiethingy
int ambientIR; //ambient light vars
int ambientLCR;
int LCR = 5, IR = 0;//declare ports
boolean now = LOW, prev = LOW;//for counter
int myglobal = 0;//for counter
void setup() // run once, when the sketch starts
{
//Serial.begin(9600); //debug
for (int i = 2; i <= 13; i++){ //initialize ports
int pin = i;
pinMode(pin, OUTPUT);
}
//test the led array by running back and forth
for (int j = 2; j <= 13; j++){
digitalWrite(j, HIGH);
delay(150);
}
delay(300);
for (int j = 2; j <= 13; j++){
digitalWrite(j, LOW);
}
delay(40); //prevent interferance from test
ambientIR = analogRead(IR);
ambientLCR = analogRead(LCR);
}
void loop(){
int compLCR = ambientLCR - 100;
int crntLCR = (analogRead(LCR));
if (crntLCR < compLCR) {
cRange ((2), (3), HIGH);
ambientIR = analogRead(IR);//needed so that counter/alarm doesnt change when lights are turned on/off
}
else if (crntLCR > (ambientLCR - 10)){
cRange (2, 3, LOW);
ambientIR = analogRead(IR);
}
// int compIR = ambientIR - ((analogRead((1)) / 5)); //in case you want to change the threshold with a pot
int compIR = ambientIR - 50;
prev = now;
// digitalWrite((2), HIGH);
// digitalWrite((3), HIGH);
int crntIR = analogRead(IR); //current IR reading
if (crntIR < compIR){
now = LOW;
}
else if (crntIR > (ambientIR - 10)){ //fuzzy logic prevents flashing
now = HIGH;
}
delay(50); //sampling speed
/*
Serial.print("\n crnt IR "); //for diagnostics
Serial.print(crntIR); //for diagnostics
Serial.print(" crnt LCR "); //for diagnostics
Serial.print(crntLCR); //for diagnostics
*/
if ((prev == HIGH) && (now == LOW)){ //tracks beam breaks
myglobal++;
}
// begin binary counter
int mylocal = myglobal;
int compare2 = 512; // compare to bit value: 512 for a 10 led display
for (int iw = 13; iw >= 4; iw--){ //high pin (13 here) to low pin (4)
if (mylocal >= comp2){
digitalWrite(iw, HIGH);
mylocal = mylocal - comp2;
}
else {
digitalWrite(iw, LOW);
}
compare2 = compare2 / 2;
}
}
void cRange(int lo, int hi, boolean hilo) //my handy dandy function to change a range of ports
{
for (; lo <= hi; lo++){
digitalWrite(lo, hilo);
}
}

ps. i added comments and now Mr. Compiler no comprende cRange. w/e

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: