Exercise 02 – R.L.D.M.D.

Real Life Dramatic Moment Device

Abstract: This device dramatizes the everyday life with your own choice of soundtrack!

Why: Why not? We deserve to live life in silver-screen quotations.

Use: Whenever and wherever appropriate and inappropriate.


Schematic:

untitled-2

Arduino code:

————————————————————————————–

int sensor = 0; //IR read-in pin :: analogue
int pinOut = 7; //relay-control pin  :: digital
int counter = 0;
int play_time = 1500;
int add_num_reading = 14;
int delay_rate = 300; //1/3 of a second :: 10/30 frames

int lowEnd = 280; //the low end of the proximity reading
int highEnd = 1100; //the high end of the proximity reading

void setup()
{
pinMode(pinOut, OUTPUT);
}

void loop()
{
int val = 0;

val = readVal(sensor);

//the following condition forces the target to be in porximity for a set amount of time
if(isValid(val))
{
counter++;
}
else
{
if(counter>0)
{
counter–;
}
}
delay(300); //wait 1/3 of a second :: 10/30 frames to initialize another sampling

if(counter>6) //make sure the object is in proximity for some duration; avoid passing objects
{
digitalWrite(pinOut, HIGH); //turn on iPod
delay(play_time); //leave the iPod on for the durration of play_time
if(!isValid(readVal(sensor)))
{
counter = 0; //reset counter
digitalWrite(pinOut, LOW);//turn off iPod
}
}
}

int readVal(int sensorNum) //mass sampling function
{
int readVal;
readVal = analogRead(sensorNum); //initial reading

for(int i=0;i<add_num_reading;i++) //addtional number of samplings
{
readVal += analogRead(sensorNum);
}

return (readVal/add_num_reading+1); //return the average of (the initial readi + additiona; readings) :: smooth out noise
}

boolean isValid(int input) //this function verifies whether of not an object is in proximity
{
if(input>lowEnd && input<highEnd)
{
return true;
}
else
{
return false;
}
}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

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