So, I have a circuit and sketch for moving a servo to 33° if you press on a force-sensitive resistor(pin A0) and gradually press harder over 1.65 seconds. After that it will check how much light there is from a light dependent resistor(pin A1) and do nothing while the light is over a certain threshold. If the light goes below that threshold, it moves the servo to 130°. I would like to make it where it would work like this except I would instead tap a certain rhythm on the force resistor, at any speed. What modifications to the code would let it do this? Here’s part of my code below:

``````val = analogRead(fr); //sample 1 of the force resistor
delay(200);
delay(200);
delay(200);
delay(200);
delay(200);
delay(200);
delay(200);
delay(200);
delay(200);
delay(200);
delay(200);
delay(200);
if (val < val1 && val1 < val2 && val2 < val3 && val3 < val4 && val4 < val5 && val5 < val6 && val6 < val7 && val7 < val8 && val8 < val9 && val9 < val10 && val10 < val11) { //if each sample is less than the next
myservo.write(33); //move the servo to 33°
ldrval = analogRead(ldr); //get a value from the light dependent resistor
while (ldrval > 19) { //while the light is above a threshold
delay(2500); //delay //do nothing for 2.5 seconds
ldrval = analogRead(ldr); //check the light again
}
myservo.write(130); //move the servo back to 130°
delay(200);
}
``````

Thanks,
Greg