Benedetta had recommended that we do this lab. Truthfully, I’m not sure why detecting the change in voltage output overtime is very useful. Here are a few other questions I have:
- How long should the detection time be?
- How to detect the noise value of an analog sensor?
Since digital sensors can only sense two states, what’s important for detecting digital sensor change are the rising and falling edges.
To detect the state change, we need to store the current state of a button as well as the previous state:
It’s more complicated with analog sensor detection. We need to detect the peak value from the sensor. Like with the digital sensor, both the current and the previous states are tracked. To find the peak, we pick a threshold that would be below the peak. Each time the sensor value rises above the peak, the sensor value is stores as the peak. This happens continuously until the peak value is always above the sensor value.
With analog sensors there are often noise in the sensor reading that interfere with peak readings. To remove the noise, the code is modified as such: