int SENSOR_PIN = 2; int tiltVal; int prevTiltVal; int count=0; void setup() { pinMode(SENSOR_PIN, INPUT); // Set sensor pin as an INPUT pin Serial.begin(9600); } void loop() { // read the state of the sensor tiltVal = digitalRead(SENSOR_PIN); // if the tilt sensor value changed, print the new value if (tiltVal != prevTiltVal) { if (tiltVal == 0) { count= count + 1; Serial.println(count); if (count >= 8){ Serial.println("Yay, you have done one set of curls"); count = 0; } } prevTiltVal = tiltVal; } delay(10); }
I found the most difficult part of this recitation to be coding the additional steps. I turned to my partner, who had turned to a lab assistant, to get the code. But, I was able to complete step four on my own upon gaining a better understand of the language from the previous slides and by referencing the slide deck from lectures. The soldering was a pleasant experience albeit there was some difficulty in wrapping the tilt sensor and the wire together. I would assume that the tile transitions between high and low when the tilt sensor is slightly able level with the ground, as the serial monitor would continuously repeat the low value when I rested my arm on the desk. I unfortunately was not able to test whether rotation or shaking the device would have an effect. I believe that the device could be used by anyone if they applied it correctly.