Codes
Because there are two input devices of our project, we have to define them in the codes of Arduino. First is identifying the signals from two devices, so two pin modes are setup as shown in the image. Next is calculating the distance of the people and the sensor. Distance is the time in microseconds from the sending of the EchoPin to the reception of its echo of an object, whose counting unit is centimeter. Then there are two algorithms which can get rid of the first data and the largest data from the five distances we detected, so that the program can send a relatively accurate data to Processing.
To interact with the “cat”, which is actually in the videos, the three videos associated with the three logics are inserted in Processing to be run. Then, the data sent from Arduino gained by the two input devices are transferred to Processing.
Next is distinguishing the three probabilities to generate three results: When the distance is more than 80cm, and the button is not pressed, it means “people is/are away”, the result of “NewCMDFlag=1” will be presented; when the distance is shorter than 80cm, and the button is not pressed, it means “people get close”, the result of “NewCMDFlag=2” will be presented; when the distance is shorter than 80cm, and the button is pressed, it means “people get close, but feed”, the result of “NewCMDFlag=3” will be presented.
The three results are linked with the three videos inserted at the beginning of the codes, so the following steps are just play the specific ones in the certain situations. And the last step is to stop the videos.