4/9/2022
In this recitation, we tried a fun exercise– to build a system that can count your curl times by the sensor. In the group with Leon, we first made our “curl sensor”, it’s not hard to cut the wires and connect them with the sensor, so we soon complete this mission.
Then the task 2 required us to test the sensor, we use the Arduino code to do this job, and it turns out worked well.
Here is my code:
int SENSOR_PIN = 2; int tiltVal; void setup() { pinMode(SENSOR_PIN, INPUT); // Set sensor pin as an INP Serial.begin(9600); } void loop() { // read the state of the sensor tiltVal = digitalRead(SENSOR_PIN); Serial.println(tiltVal); delay(10); }
The step 2 needs us to refine the code so that it will works more logically, we follow the guideline and refined our code, here is the code and our video:
int SENSOR_PIN = 2; int tiltVal; int prevTiltVal; 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(tiltVal); prevTiltVal = tiltVal; } delay(10); }
In this step we discussed about the code and figured out how it works, which helped us a lot during our next step’s processing.
Step 3 and 4 was put together by us since they are really related to each other, we do as the guideline recommends and I also made a few changes in my code.
And in the step 5 I made the final change to my work- I added a buzzer and it will tone when you finish 2 sets of curls, and make congratulate to you, during the process I also asked the professor about the program and Professor Gottfried helped me a lot, and finally I decided to use jump to fulfill my challenge.
Here is my final code:
int SENSOR_PIN = 2; int tiltVal; int prevTiltVal; int count=0; int goal=32; 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; count=count+1; if (count%2==0){ Serial.println("One turn finished, Strengthen Keqing!"); if (count%16==0){ Serial.println("Yay, you have done one set of curls"); if (count%32==0) {Serial.println("Congratulations!"); tone(8,440); } else{ noTone(8); } } } } delay(10); }
In all, this recitation taught me that we should be creative in programming and designing. I feel that I’ve really learned a lot in this class.