Recitation 3: Workout

First part: step 4 (bicep curls) :

videos:

codes:

int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int total = 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) {
Serial.println (total);
total = total + 1;
prevTiltVal = tiltVal;
}
if (total == 8){
Serial.println (“Yay, you’ve done a set of curls”);
total = 0;
}
delay(10);
}

Second part: Step 5: Exercise Challenge

So, as the challenge, I made the program to say “finish exercise!” when the user already done 8 times of bicep curl.

video:

codes:

int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int total = 0;

void setup() {
pinMode(SENSOR_PIN, INPUT); // Set sensor pin as an INPUT pin
Serial.begin(9600);
if (total==1){
Serial.println(“start to exercise!!!”);
}
}

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) {
Serial.println (total);
total = total + 1;
prevTiltVal = tiltVal;
}
if (total == 8){
Serial.println (“Yay, you’ve done a set of curls”);
total = 0;
}
if (total == 0){
Serial.println (“finish the exercise!”);
}

delay(10);
}

Third part: The preliminary sketch

Forth part: Reflection

According to the program, when the sensor turns right, the number becomes 1 and when the sensor turns left, the number also turns to 0, just like the following video.

And if you place the sensor horizontally, the number will switch between 1 and 0 endlessly, which is also the same result when shake the sensor with wires. What’s more, if you hold the wires several centimeters away and tilt it, the result of the number will be uncertain as you can’t have a good control of the wires that attached to the sensor, like the video.

Meanwhile, as for the users, I think everyone that the has the ability to crimp their arms can use this device to do some exercise.

Leave a Reply

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