Wednesday, May 13, 2015

Final Project: Code Work

The Goal:
To write a code that would function well with our final idea and meet the needs of our design logistically.

Reference Codes:
The first thing that we did was look back at old codes we have done in the class in order to see if there was anything we could implement into this code. The SOS code that I have included below reminded us how to make a function within the code itself. This function technique can be seen in our later codes.


Initial Code:
This was our first try at the code for this project. First we create the appropriate integers (buttonState1, 2...) and set them equal to zero to make it start counting at zero, Next we declare the LED lights as outputs since they are receiving input to make them light up and we declare the buttons a inputs since they are getting pushed. Then we begin the loop by making the arduino read the state of the buttons. After this, we create a set of if statements that basically say if the two buttons on one side are both on then the light will turn on for 2 seconds then off for 1 second and if this this condition is not true then the LED should be "LOW" meaning it is off. If this code were to be actually implemented we would extend the second delay to ensure the mat stays off throughout the rest of the lesson so it is not a distraction. The same if statement is then made for the other side.


Final Code:
We modified the code slightly for our final by adding internal functions like those in the SOS code. Most of the code is the same except for the introduction of the functions "short1," "short2," "long1," and "long2."



Further Improvements: 

  1. As I stated above, if this code were to be actually implemented then the refractory period after the light initially comes on would span the entirty of the lesson so it would not become a distraction to the kids.
  2. Another thing we could do would be to alter the code so that when one side was pressed then the other side would be inhibited completely. As of right now if both sides are pressed then one side will light up followed by the other side. The two would alternate back and forth until they were no longer pressed. Since in reality the refractory period would be much longer, it stops becoming an issue. 
  3. It would also be interesting to make the code so that only one button on the side needed to be pressed to make the code execute. We didn't feel that for our purposes this was necessary because anywhere pressure was applied both buttons on that side would be pressed since the mats were backed by stiffer plastic and since the buttons themselves are very sensitive. 


Reflection:
After the complex coding needed for the sciborg, this code seemed much simpler, however there were still small nuances in the coding language that tripped us up at times like the use of &&.

No comments:

Post a Comment