Recitation 7: Serial Communication by Linhui

Lab Date: April 19, 2019
Instructor: Marcela

Exercise 1

At first, when I opened the multiple value serial-communication to the arduino, I found it didn’t work and I asked the Tristan for help. We  checked and tried together and we found a very small mistake, but this mistake stops the whole process. I should use serial. println(); instead of serial.println(‘,’). Otherwise, it will never transform the data into processing because it is still on the loop. It is an important point that I ignored in class. 

[code] Arduino

// IMA NYU Shanghai
// Interaction Lab
// For sending multiple values from Arduino to Processing

void setup() {
Serial.begin(9600);
}

void loop() {
int sensor1 = analogRead(A0);
int sensor2 = analogRead(A1);

// keep this format
Serial.print(sensor1);
Serial.print(“,”); // put comma between sensor values
Serial.print(sensor2);
//Serial.print(“,”);
//Serial.print(sensor3);
Serial.println(); // add linefeed after sending the last sensor value

// too fast communication might cause some latency in Processing
// this delay resolves the issue.
delay(100);
}
[/code]

//Processing

// IMA NYU Shanghai
// Interaction Lab
// For receiving multiple values from Arduino to Processing

/*
* Based on the readStringUntil() example by Tom Igoe
* https://processing.org/reference/libraries/serial/Serial_readStringUntil_.html
*/

import processing.serial.*;

String myString = null;
Serial myPort;

int NUM_OF_VALUES = 2; /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/
int[] sensorValues; /** this array stores values from Arduino **/

void setup() {
size(500, 500);
background(0);
setupSerial();
}

void draw() {
updateSerial();
float posX=map(sensorValues[0],0,1023,0,500);
float posY=map(sensorValues[1],0,1023,0,500);
noStroke();
fill(255);
ellipse(posX,posY,30,30);
print(posX);
print(“,”);
print(posY);
println();

//printArray(sensorValues);

// use the values like this!
// sensorValues[0]

// add your code

//
}

void setupSerial() {
printArray(Serial.list());
myPort = new Serial(this, Serial.list()[ 4 ], 9600);
// WARNING!
// You will definitely get an error here.
// Change the PORT_INDEX to 0 and try running it again.
// And then, check the list of the ports,
// find the port “/dev/cu.usbmodem—-” or “/dev/tty.usbmodem—-”
// and replace PORT_INDEX above with the index number of the port.

myPort.clear();
// Throw out the first reading,
// in case we started reading in the middle of a string from the sender.
myString = myPort.readStringUntil( 10 ); // 10 = ‘\n’ Linefeed in ASCII
myString = null;

sensorValues = new int[NUM_OF_VALUES];
}

void updateSerial() {
while (myPort.available() > 0) {
myString = myPort.readStringUntil( 10 ); // 10 = ‘\n’ Linefeed in ASCII
if (myString != null) {
String[] serialInArray = split(trim(myString), “,”);
if (serialInArray.length == NUM_OF_VALUES) {
for (int i=0; i<serialInArray.length; i++) {
sensorValues[i] = int(serialInArray[i]);
}
}
}
}
}

Exercise 2

// IMA NYU Shanghai
// Interaction Lab
// This code receives one value from Processing to Arduino

char valueFromProcessing;
int Pin = 7;

void setup() {
Serial.begin(9600);
pinMode(Pin, OUTPUT);
}

void loop() {
// to receive a value from Processing
while (Serial.available()) {
valueFromProcessing = Serial.read();
}

if (valueFromProcessing == ‘L’) {
noTone(8);
tone(7,350,200);
delay(10);
} if (valueFromProcessing == ‘M’) {
noTone(6);
tone(7,400,500);
delay(10);
} if (valueFromProcessing == ‘N’) {
noTone(7);
tone(7,600,300);
delay(10);
}

// too fast communication might cause some latency in Processing
// this delay resolves the issue.
delay(10);
}

// IMA NYU Shanghai
// Interaction Lab
// This code receives one value from Arduino to Processing

import processing.serial.*;

Serial myPort;
int valueFromArduino;

void setup() {
size(500, 500);
background(0);

printArray(Serial.list());
// this prints out the list of all available serial ports on your computer.

myPort = new Serial(this, Serial.list()[ 4 ], 9600);
// WARNING!
// You will definitely get an error here.
// Change the PORT_INDEX to 0 and try running it again.
// And then, check the list of the ports,
// find the port “/dev/cu.usbmodem—-” or “/dev/tty.usbmodem—-”
// and replace PORT_INDEX above with the index number of the port.
}

void draw() {
if (pmouseX<width/4){
myPort.write(‘L’);
} if (pmouseX<width/5 && pmouseX > width/5){
myPort.write(‘M’);
} if (pmouseX>width/4){
myPort.write(‘N’);
}
// to read the value from the Arduino
//while ( myPort.available() > 0) {
// valueFromArduino = myPort.read();
//}
// println(valueFromArduino);//This prints out the values from Arduino
}

Preparatory Research and Analysis by Linhui Wu-Marcela

Date: April 18, 2019
Instructor: Marcela

Our initial definition only considers how many factors we involved in the project and focus on the interaction triggered by a real behavior or action. And we confused the concept of function and interaction. During the learning process, I found interaction is not necessary with a function, in other words, function is a kind of interaction. We have discussed about the aim of interaction. Some projects help the disability to draw, some can improve the traditional communication way. Interaction is around us and it can be in any forms, the light and shadow, the sound and visual art. Interaction might bridge between computer and reality. Technology is a tool to achieve interaction, complicated and simple. But technology is not a standard to evaluate the interaction. Instead of chasing complicated technology, I think the feelings what the project can bring is the most important. When I have midterm projects, during the user test session, I received many helpful comments, including “increase visual equipment” “change the language showed in the computer”, which further evolves my understanding of “interaction”. I am aware that details can help a lot. Marclea also reminded me that we are not selling products but we are showing a new way of interaction. I start to reconsider the real meaning of our projects and interaction in reflection. Focus too much on the functions might limit our imaginations. Some projects look weird but really involves users, some projects look simple but advance the relationship between people and environments, different individuals. Up to now, after I see more art projects and learn more processing skills and communicate with fellows,  my beliefs of interaction improves further.  

The “Espongia”, created by Merche blasco, is a gestural controller using the water and wood to produce sound through interactions with audio software. This project inspires me that even very simple structure can create thrilling music. The music instrument is easy to operate and reflects the emotions of players leaving the audience great impressions. Though only with one waterproof sensor, the instrument can create thousands of tones through analyzing the vibration of the water. Instead of aim-orientated, this instrument fulfills the standards of my definition of interaction, simple but showing a new interaction way with the normal things in life, the wood, the water.

Another project inspires me is the Beetbox musical instrument. With strange appearance, it attracts me and makes me happy when I see the video. You never expect that this is a musical instrument. This project applies complicated technology but all technology is invisible. The interaction is extremely easy but gives abundant experience beyond expectation.

A work I think is not very interactive is the automatic DIY vending machine, it focuses too much on the functions of the project and its use in real life but ignores the interaction between the project and users. People cannot have strong change of emotions or feelings.  It is not aligned with the standard of the interactions. It does save the time of customers and involves the interaction but it doesn’t bring strong emotional experience. Interaction is not inventing something useful but recreating the normal things and shifting our mind.  

In combination, the understanding of these three projects makes me more clear about what interaction really is. My own definition of interaction is that human beings communicate closely and produce emotional connections with a project, which improves or changes the original way of communication between human themselves or human and environments. Interaction might be in any forms, visible or invisible, sound or light, complicated or simple, and it influences people’s perception of the environment and the relationships. It further helps people to build up dialogues and exploration between themselves and culture, history, philosophy, far beyond the limitations of physical materials. 

Recitation 6: Processing Animation by Linhui

Lab Date: April 14, 2019
Instructor: Marcela

In the recitation, I choose to apply what we just learned in the lecture and I thought the smile picture is very interesting and cute. The most interesting code is the myFunction part, not only because it saves a lot of time but also it can produce work in a random position and size to increase the visual shock. The drawback of this function is that In JavaScript, if no return value is specified, the function will return undefined. I want to make the random smile move but it didn’t change color, only move positions. After trying a lot of times, I found the processing will produce more and more smile but not a limited number of smile which can move randomly. I try to put the myFunction{}; into the void draw part but it overlaps endless.  I asked Marcela for help, she told me it requires further knowledge “array”, float posX [] and posY[] to fix the x and y and then set move function. Then I choose to use keyPressed to show the random position of the “smiles”. To make it more interesting, I add a mobile ball which will change color automatically and only move in the canvas. When you pressed “q” the smiles will appear, else the smiles will not appear in the background.  The number of “smiles” is too much and makes the picture look a little bit messy. Easter recommends me to change the number of “i” and the canvas looks better. The next step of this picture, I try to move the ball based on the array key pressed. 

The video:

The code is following:

float circleX = 300;
float circleY = 0;

float xSpeed = 1;
float ySpeed = 1;
float x;
float y;
float s;
color c;
float a1 = 20;
float a2 = 30;

void setup(){
size(600,600);
background(255);
//println(addition(100,37));
//println(addition(10,3));
//myFunction(130,50, 10,color(120,30,50));
// myFunction(200,200,10, color(120,30,50));
// myFunction(100,100, 10, color(120,30,50));
x = random(width);
y = random(height);

}
void myFunction(float x, float y, float s, color c){
noStroke();
fill(c);
ellipse(x,y,s,s);
fill(255);
ellipse(x-100*0.3, y-100*0.1, s*0.05, s*0.05);
ellipse(x+100*0.3, y-100*0.1, s*0.05, s*0.05);
//mouth
arc(x,y, s*0.6,s*0.6, 0, PI);

}
void draw() {

background(0);
fill(random(255),random(255),random(255));
ellipse(circleX, circleY, 100, 100);

circleX = circleX + xSpeed;
circleY = circleY + ySpeed;

if (circleX < 0 || circleX > width) {
xSpeed = xSpeed * -1;
}

if (circleY < 0 || circleY > height) {
ySpeed = ySpeed * -1;
}

}

void keyPressed (){
if(key == ‘q’){

for(float i = 0; i < 10; i ++){
myFunction(random(width), random(height), random(10,100), color(random(255),random(255),random(255)));

}

}

}

Additional homework:  

The last step of additional homework is diffucult. I tried many differen approaches, including for loops, but the size of circle is changing all the time and you don’t know what is the size when it closes to the cross. Finally I remeber the size also can change with the size of the circle, and at this time, I only use one value “circle”, it is very convenient and effective.

float steps = 3;
int i=0;
float x = 300;
float y = 300;
float xs = 0;
float ys = 0;
float size = 0;
int count = 0;
int cycle = 75;
float s = 50;

void setup(){
size(600,600);
colorMode(HSB, 255);
frameRate(40);
size(600,600);
rectMode(CENTER);
}

void draw(){
if (keyPressed) {
if (keyCode == UP) {
ys=-15;
xs=0;
} else if (keyCode==DOWN) {
ys=15;
xs=0;
} else if (keyCode ==LEFT) {
xs=-15;
ys=0;
} else if (keyCode == RIGHT) {
xs=15;
ys=0;
}

}
size = 125 * sin(PI * count / cycle)+225;
if (height-y<size/2f) {
ys=-15;
xs=0;
}
if (y<size/2f) {
ys=15;
xs=0;
}
if (width-x<size/2f) {
xs=-15;
ys=0;
}
if (x<size/2f) {
xs=15;
ys=0;
}
x+=xs;
y+=ys;
translate(x,y);
background(0,0,255);
fill(0,0,255);
strokeWeight(10);

stroke(i, 255, 255);
i=i+1;
if(i>255){
i=0;
}
ellipse(0,0,s,s);
s = s + steps;
if (s < 40 || s > 300 ){
steps = -steps;
}

}

Recitation 5: Processing Basics by Linhui

Lab Date: Mar. 29, 2019
Instructor: Marcela

Several Circles

I choose this picture because it uses very basic figures to create a complicated artistic conception, making me feel peaceful and comfortable. I was attracted by these circles when I first saw them. They seem distributed randomly but serve as beauty. It makes me think deeply and stare it for a long time. 

I want to use this picture as a motif and create a picture consisting of different kinds of figures. The aim of the creation is to display the beauty and peace brought by the simple geometric figure and colors. I will use processing mathematical functions and fill(); stroke(); strokeWeight(); and etc. to realize that. 

In terms of the similarities, we both use colorful circles and background to create a  peaceful feeling. We aim to realize an abstract art concept that is the beauty of figures and give the audience more imagination space. The difference is that the motif are using more traditional patining skills and distinguish some details when you look carefully.  The indistinct track of ink is very attractive. For my work, I use more geometric figures, not simply circles. I use rectangles and lines, different transparency of the color, trying to make it more complicated and keeping peaceful feelings. 

I think drawing processing is a very good means to realize drawing. I like painting but I am not good at drawing. I have good inspirations but my drawing skills are not allowed me to aachieve that. Processing is a very good tool which helps to realize my inspiration. It is very convenient and aesthetic. If I use traditional painting tools, it is impossible for me to finish it and I don’t know how to produce the color I want. This proved that technology is a powerful tool to realize your idea.

The code is below:

background(0,0,0);
size(600,600);
fill(30,127,198,100);
rect(100,100,300,300);
fill(30,198,155,100);
rect(300,300,200,200);
fill(150,198,30,100);
rect(50,200,100,100);
stroke(255,255,255,100);
strokeWeight(10);
fill(47,28,111,120);
ellipse(300,300,200,200);
noStroke();
fill(0,0,0,100);
ellipse(250,250,60,60);
fill(164, 99, 209, 100);
ellipse(300,200,40,40);
fill(222,130,18);
ellipse(500,500,10,10);
fill(26,8,131,100);
ellipse(300,330,20,20);
fill(227,181,55,70);
ellipse(350,350,30,30);
fill(277,7,33);
ellipse(550,500,5,5);
fill(7,277,188);
stroke(13,28,160);
strokeWeight(8);
ellipse(400,100,50,50);
noStroke();
fill(#E337C4);
ellipse(200,100,40,40);
fill(152,35,232);
ellipse(400,500,50,50);
stroke(250,228,156);
strokeWeight(2);
fill(#7197B7);
ellipse(390,480,15,15);
noStroke();
fill(240,87,87,130);
rect(380,180,150,150);
fill(232,64,2,100);
rect(500,530,60,60);
fill(2332,2,217,100);
rect(200,400,100,100);

stroke(255,255,255);
strokeWeight(2);
fill(#16334B);
ellipse(450,300,10,10);
noStroke();

fill(18,174,203);
ellipse(380,380,80,80);
fill(#0D92FC);
ellipse(380,380,10,10);
stroke(232,199,35);
strokeWeight(5);
ellipse(200,400,10,10);
noStroke();
fill(#FC0D45);
ellipse(390,360,10,10);
fill(0,0,0);
ellipse(400,360,8,8);
fill(#ED1648);
ellipse(580,580,10,10);
fill(#FCE50D);
ellipse(570,570,20,20);
fill(137,89,77,100);
ellipse(479,489,20,20);
fill(242,27,45,100);
ellipse(200,350,50,50);
fill(26,113,9,100);
ellipse(200,330,40,40);
fill(30,198,174,100);
ellipse(200,400,100,100);
stroke(93,115,170,100);
strokeWeight(10);
line(0,0,400,400);
line(400,400,600,0);
line(200,200,0,600);

The final version:

Massage Clothe and Blowing Hat-Linhui-Marcela

Presentation Date: Mar. 26, 2019
Instructor: Marcela
 Partner: Zoe

                 Massage Clothe & Blowing Hat-Linhui-Marcela

    In my research project, I have research on different kinds of interactive artistic works,  and I am appreciated in the robotic arm. I think this robotic arm is a great practice of interaction. The interaction reflects on the high communication level between users and the arms. The communications are realized in the form of entertainment and assistance functions. Most importantly, it brings the emotional change of users. It was also very beneficial for the disability. The robotic arms can “read” people’s mind and do the instructions. People don’t have to read using explanation or instructions. Robotics arm combines people, environment and some other different organisms. You can obviously feel the interaction power through the video when it does those series of things. It promotes my understanding of a good interactive project that it should display a new way of communication and interaction, solve a current problem, or entertain users. A good interactive project is not necessarily a complicated one,  for example, the “elastic shoe” achieves great interaction between people and people.  Users only need to push the button to adjust the height of the shoe. Users can communicate with others in a new way. Another project that inspires me a lot is Masakazu Takasu’s rabbit ears. His project is very interactive, the ears can change direction and focus on the audience. Sometimes, an interactive project can reflect the inner emotional change of users to improve the interaction.  

(Masakazu-takasu): http://videos.theconference.se/masakazu-takasu-interactive-design-from-japan

    The projects all inspire me to create a project that focuses on a new way of interaction. Our project aims to show the emotional change of people in different conditions by detecting the heart rate. Based on this principle, our project tries to provide relief for the users and make them feel relaxed. The difference between some technical devices, for example, Apple Watch, and our project is that we try to make our project more creative and interesting instead of unfeeling data. Our contribution is to transform those data into a more interactive way to make people be aware of and we are considering what is the next step that is helping them better adapt to different conditions and communicate with others. Our main intended group of people is who is easy to get nervous and be shy to express personal feelings. Our project visualizes the intangible emotion and explores a new interesting interaction way which appeals to the users. 

     First of all, we think users might be more familiar with the things available in life and are willing to try them without alienated feelings. Therefore, we choose wearable equipment as our physical isotopic carrier. In consideration the main aim of our project, wearable equipment is more convenient to receive personal information. We decide to choose cloth and hat as carriers. People might be concerned about how their heart being detected and what they need to do. We decide to use the ear clip to detect, trying to simplify this step because the ear clip reacts sensitively. People’s skin might be directly touched with the massage cloth when they are doing massage. Based on this, we decide to use cotton to wrap the end of the DC motor. We try to use the vibration motor but the vibration motor from Lab is powerless and the vibration level is not strong. Therefore, we use the dc motor and cotton to replace the vibration motor. People might need to receive information about the rate change, how we can visualize that? We use LED signal with a different color to represent a different range of heart rate. People might want to listen to some music to relax when they feel nervous. We add a buzzer to make music when the heart rate attains a certain amount. The criteria we select our devices is safety, portable and effective. We tried RGB light as an indication but we considered that the continuous changing of the light might make users confused. Vibration sensor might be another option but it is not feasible, We tried to use it as an input, but the vibration sensor cannot detect everyone’s heart rate. It also can not reflect the specific data of heart rate and it is not stable. Ear clip is more sensitive, which is suitable for most of the people, even though it doesn’t work sometimes. In terms of the button, at first, we use the normal button to control the circuit but the current is not stable, we use a switch that solves the problem. 

    The first most important step of our project is the evolving of ideas. When we decide to produce massage cloth, we begin to use the 3-D design platform “Autodesk” to build a model for our dress, and choose the dc motor instead of a vibration motor, this indicates a potential problem. The electricity in the circuit is not stable, which directly influences the heart rate data which further cannot stop the motor. We need to prevent the motor from any resistance power, therefore, we change our ideas based on currently available technology. We develop it into a blowing hat before test user but we don’t want to give up the massage cloth and try to use a new connection way, in this situation, it will be a piece of separate equipment from the ear clip. The second challenge is how to operate and edit coding. My partner and I are the first time to access coding and we spent a lot of time reading materials and seeking help from fellows. We grab additional functions from trials and errors and we found coding requires strong logic and patience. Even you copy from the library, you need to revise and understand how it operates. What’s more, small details may cause a big difference. Simultaneously, when we basically finish the coding, we should simplify it and improve it. For example, deleting some data and functions that are not useful to our project aims. In the test user, we receive many positive and useful suggestions.  

Subject 1: ” it is interesting, but what if there are some LED to indicate what I need to or what circumstances I am under…”

Subject 2: “Can you shorten the waiting time for the heart rate consequence?” 

Subject 3: ” the showing sentence “heart rate detection error” is not interactive, you might use another frame to increase the interaction…”

Subject 4: ” there is some improvement space for the appearance, you might have a laser cut box to hide those wires…”

Subject 5: “you might provide a brief instruction because I am a liitle confused when I use it…”

For the feedback, we make some adjustments. We add three LED outputs (green, red and yellow), which represents different ranges of heart rate. We use digitalWrite(); and if(); conditions to finish this step. The coding is below :

We add buzzer which only makes melody when the heart rate over 120.

We check the coding and change the function to shorten the time. 

heart_rate = 300000 / (temp[5] – temp[0]);  

We further change the dialogue sentence from “detection error” to “walking dead” which sounds more interesting and interactive.

if (sub > max_heartpluse_duty) //set 2 seconds as max heart pluse duty
{
data_effect = 0; //sign bit
counter = 0;
Serial.println(“You don’t have heart rate, you are a WALKING DEAD” );

These adoptions are effective to improve the interaction level of our project in terms of efficiency of the project and multiple sense feelings received by users. 

Our project aims to visualize show the emotional change of users in different conditions and explore a new way of interaction, and at the same time the project, in turn, influences the emotion and feelings of users. My project uses fans, LED and buzzer as Output to record and show the emotional change. The interaction is not simply action but an intangible information change. Heart rate is the data that convey the emotional change of users. However, a part of my project comes to failure, the massage cloth. I think we might focus too much on the functions when we are making the massage cloth. We are not selling a product, instead, we should create an interactive project. We haven’t kept in mind all the times, which contributes to failure. What’s more, we should evolve or change our idea when we found the technology limitations. Failure is also a learning process. Basically speaking, our project results and users’  response align with our expectation, but we should have done better considering the failure we made. Users were aware of their emotional change when they interacted with our product. If we have more time, we want to re-design the cloth and produce a cloth that can show the emotion change of people instead of a very specific functional product. Recommend by Marcela, I reviewed many projects from Farahi who gives me further thinkings and inspirations. The significance of the failure is that interaction is not simply a kind of functions or a kind of service but a kind of mutual communication. When we focus too much on how well a product can serve the people or how welcome it will be in the market, our sights will be narrowed down. Interactive is not equal to usefulness or fancy appearance but contribute to a better life of human beings. What I learned from the accomplishments is that a great artwork should teamwork and a clear goal and require constant adjustments and improvements based on user’s feedback and instructors’ suggestions. 

Additional  document:

#define LED 13//indicator, Grove – LED is connected with D4 of Arduino
boolean led_state = LOW;//state of LED, each time an external interrupt
boolean motor_state = HIGH;
//will change the state of LED
unsigned char counter;
unsigned long temp[21];
unsigned long sub;
bool data_effect = true;
unsigned int heart_rate;//the measurement result of heart rate

const int max_heartpluse_duty = 1000;//you can change it follow your system’s request.
//2000 meams 2 seconds. System return error
//if the duty overtrip 2 second.
#include “piches.h”
int motor = 4;
int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4
};
void setup()
{
pinMode(6, OUTPUT);
pinMode(9, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(motor, OUTPUT);
//pinMode(LED, OUTPUT);
// iterate over the notes of the melody:

Serial.begin(9600);
Serial.println(“Please ready your chest belt.”);
delay(5000);
arrayInit();
Serial.println(“Heart rate test begin.”);
attachInterrupt(0, interrupt, RISING);//set interrupt 0,digital port 2
}
void loop()
{
if ( heart_rate > 120) {
digitalWrite(9, HIGH);
} else {
digitalWrite(9,LOW);
}
if ( heart_rate > 60 && heart_rate < 90) {
digitalWrite(10, HIGH);
} else {
digitalWrite(10,LOW);
}
if ( heart_rate > 90 && heart_rate < 120 ) {
digitalWrite(11, HIGH);
} else {
digitalWrite(11,LOW);
}

for (int thisNote = 0; thisNote < 8; thisNote++) {

// to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);

if ( heart_rate > 90 ) {
tone(8, melody[thisNote], noteDuration);
} else {
noTone(8);// stop the tone playing:
}
// to distinguish the notes, set a minimum time between them.
// the note’s duration + 30% seems to work well:

}

//digitalWrite(LED, led_state);//Update the state of the indicator
}
/*Function: calculate the heart rate*/
void sum()
{
if (data_effect)
{
heart_rate = 1200000 / (temp[20] – temp[0]); //60*20*1000/20_total_time
Serial.print(“Heart_rate_is:\t”);
Serial.println(heart_rate);
if ( heart_rate > 90 && motor_state == LOW) {
motor_state = HIGH;
} else if ( heart_rate < 90 && motor_state == HIGH){
motor_state = LOW;
}
digitalWrite(motor, motor_state);
//delay(500);
}

data_effect = 1; //sign bit
}
/*Function: Interrupt service routine.Get the sigal from the external interrupt*/
void interrupt()
{
temp[counter] = millis();
//Serial.println(counter, DEC);
//Serial.println(temp[counter]);
switch (counter)
{
case 0:
sub = temp[counter] – temp[20];
// Serial.println(sub);
break;
default:
sub = temp[counter] – temp[counter – 1];
// Serial.println(sub);
break;
}
if (sub > max_heartpluse_duty) //set 2 seconds as max heart pluse duty
{
data_effect = 0; //sign bit
counter = 0;
Serial.println(“You don’t have heart rate, you are a WALKING DEAD” );
arrayInit();
}
if (counter == 20 && data_effect)
{
counter = 0;
sum();
}
else if (counter != 20 && data_effect)
counter++;
else
{
counter = 0;
data_effect = 1;
}

}
/*Function: Initialization for the array(temp)*/
void arrayInit()
{
for (unsigned char i = 0; i < 20; i ++)
{
temp[i] = 0;
}
temp[20] = millis();
}