I use this week to build the prototype as well. I have visited the in- campus workshop to solve the problem that I have faced last week by consulting the tutor. The first problem that I have solved is that the servo keeps shaking and can be used without the flex sensor. The tutor said that the code is correct, the problem is that the system is very sensitive, that the servo change ever second base on the mini change of the data of the flex sensor and the ultrasonic sensor. To make it stable, I need to observe the live value when I bending the flex sensor to find the average value and try to set the value around the average value to see which one can make the system more stable. The code change from the left picture below to the right one.
The second problem is that the LED strip cannot turn off by the ultrasonic sensor then automatically turn on with different light effects in a few seconds later. To solve the problem, the count of the loop running should be recorded. The tutor has given me the suggestion that I can learn from the sample in the Arduino IDE, which called “state change detection”, it is a code that presents using the button to control the led base on the times of the button been pushed. It is similar to what I need.
Then, I have learned how to making the function that two buttons keep pressing to make the LCD work as a timer, if only one button keeps pressing, the LCD timer will stop. This function present when user put their phone into the box and sit on the seat the time will be counted as their study time, if the user takes out their phone or leave the seat, that means the user does not sit for study, so the time should not be count as study time, the timer will stop. The code here is similar to the sample code “state change detection” as well.