Movement Record & Visualizer

20160923_154302

/////////////////////////////////////////////// Video //////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////

————————————————————————————————

The recorder part keep track the time you spend in each space range in a time period, and visualize you time and space through the lights.

The longer people spend away from the device, the longer short LEDs blink.

The longer people spend near to the device,  the longer tall LEDs blink.


###################      Code Source   #####################

Read Sonar Sketch

Multi- control sketch

#####################      Source Code       #####################

// lights from left to right 1,2,3,4,5 correspond to digital 1,2,3,4,5
// echo pin 7, trig pin 8
// ———————————————————
// define pins
#define TRIG_PIN 8
#define ECHO_PIN 7

#define LIGHT_1 9 //—
#define LIGHT_2 2 //—–
#define LIGHT_3 3 //——–
#define LIGHT_4 4 //—–
#define LIGHT_5 5 //—
//———————————————————-
// define constant values
int count1 = 0;
int count2 = 0;
int count3 = 0;
int count4 = 0;
int count5 = 0;
int count = 0;
//distance limit of sensor cm
#define MAX_DISTANCE 450
#define SOUND_SPEED 34000
#define TIMEOUT (2 * MAX_DISTANCE * 1000000) / SOUND_SPEED
void setup(){
Serial.begin(9600);

pinMode(TRIG_PIN, OUTPUT);
digitalWrite(TRIG_PIN, LOW);
pinMode(ECHO_PIN, INPUT);

pinMode(LIGHT_1, OUTPUT);
digitalWrite(LIGHT_1, LOW);
pinMode(LIGHT_2, OUTPUT);
digitalWrite(LIGHT_2, LOW);
pinMode(LIGHT_3, OUTPUT);
digitalWrite(LIGHT_3, LOW);
pinMode(LIGHT_4, OUTPUT);
digitalWrite(LIGHT_4, LOW);
pinMode(LIGHT_5, OUTPUT);
digitalWrite(LIGHT_5, LOW);
}

// return the distance of each interval
int pin_sonar(void){
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
long pulse_length = pulseIn(ECHO_PIN, HIGH, TIMEOUT);

if (pulse_length > 0){
float distance = (pulse_length * 1e-6 * SOUND_SPEED) / 2;
return round(distance);
}
else{
return 0;
}
}

void up_1(void){
digitalWrite(LIGHT_1, HIGH);
delay(100);
digitalWrite(LIGHT_1, LOW);
delay(50);
}

void up_2(void){
digitalWrite(LIGHT_2, HIGH);
delay(100);
digitalWrite(LIGHT_2, LOW);
delay(50);
}

void up_3(void){
digitalWrite(LIGHT_3, HIGH);
delay(100);
digitalWrite(LIGHT_3, LOW);
delay(50);
}

void up_4(void){
digitalWrite(LIGHT_4, HIGH);
delay(100);
digitalWrite(LIGHT_4, LOW);
delay(50);
}

void up_5(void){
digitalWrite(LIGHT_5, HIGH);
delay(100);
digitalWrite(LIGHT_5, LOW);
delay(50);
}

void loop(){
int threshold = 100;

int distance;
distance = pin_sonar();
Serial.print(distance);
Serial.print(“\n”);

if (distance >= 60){
count1++;
count5++;
count = count + 2;
}
else if (distance >= 30 && distance < 60){
count2 ++;
count4 ++;
count = count + 2;
}
else if (distance < 30 && distance > 0){
count3 ++;
count++ ;
}

// light up
if (count >= 100){
Serial.print(“huhuhuh\n”);
// light 1
delay(500);
for (int i = 0; i < count1; i ++){
up_1();
}
for (int i = 0; i < count2; i ++){
up_2();
}
for (int i = 0; i < count3; i ++){
up_3();
}
for (int i = 0; i < count4; i ++){
up_4();
}
for (int i = 0; i < count5; i ++){
up_5();
}
count = 0;
count1 = 0;
count2 = 0;
count3 = 0;
count4 = 0;
count5 = 0;
}
Serial.print(“count = “);
Serial.print(count);
Serial.print(“\n”);

delay(100);
}