Recitation – 9/30 – Workout

Videos

Here is a short video of me demonstrating how my bicep curl counter works!

 

Here is a short video of me demonstrating how my Leg-Curl counter works! (The serial monitor was not working when recording the LED for some reason)

 

 

Code for Bicep Curls

int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int bicepCurls;

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 == 0){
      bicepCurls++;
      Serial.print("You have completed ");
      Serial.print(bicepCurls);
      Serial.println(" Bicep Curls!");

      if(bicepCurls == 8){
        bicepCurls = 0;
        Serial.print(" Yay, you've done one set of curls!");
      }
    }
  }

  delay(10);
} 

Code for Leg Curls 

int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int legCurl;

void setup() {
  pinMode(SENSOR_PIN, INPUT); // Set sensor pin as an INPUT pin
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

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 == 0){
      legCurl++;
      Serial.print("You have completed ");
      Serial.print(legCurl);
      Serial.println(" Leg Curls!");
      
      if(legCurl == 8){
        Serial.println("Yay, you've done one set of leg curls!");
        legCurl = 0;
        digitalWrite(13, HIGH);
        delay(1000);
        digitalWrite(13, LOW);
      }
    }
  }
  delay(10);
}
 

Illustrations

Here are some illustration sketches of how an individual might use these training devices. I made sure to keep it into consideration whenever one repetition of the given exercise is completed to properly represent the total number of times a given exercise is done. 

 

Reflection 

I found the experiments we did today quite interesting. I played around with the sensors and ensured that my code worked as intended here and there. I noticed that the sensor needed to be rotated more than 90 degrees to change between HIGH and LOW, something that I needed to keep in mind when completing challenge 5. 

The coding part was a bit hard though, as I tried to combine various pieces of code from the examples, like trying to both play a melody and light up an LED when a set of an exercise was completed. I decided to simplify my code so I would not run into any complications. 

Working with a sensor and allowing me to use input from our physical world and manipulate information in the digital world was something intriguing and an activity I look forward to further exploring! 

Leave a Reply

Your email address will not be published. Required fields are marked *