Guys i'm working with a flex sensor and I'm trying to capture a specific value which is the moment before the user lets go of a flexed flex sensor and its represented as the top point of a falling edge as sub picture A in the picture I included. using an array I tried two methods, which can produce a close value at times but at other it will give me wrong values first I tried the following logic, whenever I detect a value below a certain threshold it indicates that a fallen edge has occurred so get me the value that came right before it as shown in sub picture C but depending on the delay this can be quite unpredictable.
the second method is to store the maximum value of but this returns the peak and it's not always the top of the fallen edge as shown in subpicture B
what do you guys suggest to capture those values? this is my code so far
bool loaded = false;
int threshold = 760;
int index = 0 ;
int _max=0;
int values[4];
int values_size = 4;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int data = analogRead(A0);
if (loaded) {
values[index] = data;
if(data>_max){
_max=data;
}
if (data < threshold) {
loaded = false;
Serial.flush();
Serial.print('a');
Serial.print(',');
Serial.print(_max);
Serial.println();
_max=0;
delay(300);
}
index++;
index %= values_size;
}
else if ( data > threshold && !loaded) {
loaded = true;
}
delay(20);
}