Recitation 3: Workout

For task1 in step4, I thought that it was similar to the code in step2 so I just skipped this step since the time is limited. For task2 in step4, I used the code below to try this and it works but I forgot to record the video that I played with my partner.
int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int times;
void setup() {
pinMode(SENSOR_PIN, INPUT);
Serial.begin(9600);
times = 0;
}
void loop() {
tiltVal = digitalRead(SENSOR_PIN);
if (tiltVal != prevTiltVal) {
prevTiltVal = tiltVal;
times = times + 1;
}
Serial.print(times);
delay(10);
}

For task3 in step4, I used this code which chooses to setting a limit by checking whether the times is the exact division of 8 as the code shows below.

int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int times;
void setup() {
pinMode(SENSOR_PIN, INPUT);
Serial.begin(9600);
times = 0;
}
void loop() {
tiltVal = digitalRead(SENSOR_PIN);
if (tiltVal != prevTiltVal) {
prevTiltVal = tiltVal;
times = times + 1;
}
Serial.println(times);
if (times % 8 == 0) {
Serial.println("Yay,you've done one set of curls.");
}
delay(10);
}

Fortunately, it works like below.

For step5, I with my partner thought that we would add a buzzer into the circuit and try the code which we learnt in the recitation2, however, the time schedule was quite tight for us and thus we did not have time to try this. During the holiday, I tried to wrote the code like below, but I am not sure whether this code will work.
int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int times;
#include "pitches.h"
int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};
int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4
};
void setup() {
pinMode(SENSOR_PIN, INPUT);
Serial.begin(9600);
times = 0;
}
void loop() {
tiltVal = digitalRead(SENSOR_PIN);
if (tiltVal != prevTiltVal) {
prevTiltVal = tiltVal;
times = times + 1;
for (int thisNote = 0; thisNote < 8; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(8);
}
}
Serial.println(times);
delay(10);
}

Here is the sketch that a person uses this interactive training device.

After reflecting all the experiments that I had with my partner during the recitation, I found several interesting discoveries about this interactive training device. The tilt transits between HIGH and LOW if I rotate it for 90 angles. The numbers shows on the Serial Monitor changes quicker than I expected as I rotate the tilt. I think this device is quite useful for people who want to record the exact amounts of their exercises because it can record the times of their raising arms and legs. Meanwhile, this device is small and light, which makes it easy to carry when people are doing strenuous exercises, just as the video below shows how I uses this device.

 

Leave a Reply

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