# Physical Computing Mitderm Project

For the midterm project, our initial idea was to create a little game involving the proximity sensor. There will be one sensor on both the left and right side, each sensor will detect the position of the player. A random value will be generated by the program to assign whether the player should go left or right for each step. To win the game, the player must choose the right side each time to reach the end of the path.

(This is the design for the sensors)

Since the sensor only works well with a black flat surface, therefore, I program the sensor to take multiple reading, discard the 0 reading the return the mean value to have an accurate reading of the distance. The second program I wrote is to detect whether the player has taken the step. This program will store an initial reading of player’s position, then keep comparing the difference between the initial reading and player’s current position, once the difference is greater than 25 cm, it will return true to indicate the player has taken a step.

After the first two programs was written, we decided to added a guidance for the player to indicate which side is the right way. So we set up a target with a pressure sensor behind it, then the player hits the target, it will trigger the sensor and the program will send out a signal showing whether the player should go left or right.

(This is the target we made for the player to shot at)

To put all the programs together into the game, I set each program to run under different time interval, once a program run out of time or receive the right signal, the next program will start running.

After we put the game together, we decided to add lighting into the game, so Richard started to write the different light effects for different parts of the game. We have left and right sweep for the guidance to indicate which way the player should go; a count down for shooting the target, a red light to indicate the wrong way, a green light to indicate the right way and a rainbow effect when the player has won the game.

However, since the program for the game and lighting were written in different board and different logic, we couldn’t combine them together. The program for the game was written in the for loop which check both timing and a boolean value, it will stop if the Boolean value change or when the time runs out. But the program for the lighting is written in a for loop which only stops when all the statements have run out. Therefore, when combining both programs together, the loop for the lighting interferes with the timing of the game, which hinders the game from running smoothly.

To sum up the project, both program runs perfectly when running independently, however, we haven’t got time to figure out the code to put both programs together for the game.