Recitation 3: Workout
1.)
2.)
CODE:
int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int count;
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) {
prevTiltVal = tiltVal;
if (tiltVal == HIGH) {
count++;
Serial.println(count);
if(count == 8) {
Serial.println(“Yay, you’ve down one set of curls”);
count = 0;
}
}
delay(10);
}
}
3.)
4.)
Reflection: My partner and I struggled to complete task 4. We completed tasks 1-3 with speed, so we carelessly attached the sensor to his arm in task 4. The sensor was placed in a horizontal position, which caused our code to print improperly. Calvin was doing complete bicep curls but the sensor had no response. We called for help and everyone said the code looked fine, so I wondered if something was wrong with our sensor. I turn it vertically, and it began to react correctly. This is because when the little ball in the sensor moves from one side to the other, it counts one.