Hi! Thanks for responding.
I'm hoping to be able to measure the response time of a touch screen. It would work by touching the screen with the force sensor and reading changes on the screen with the light sensor. The touch screen goes from fully black to fully white when sensing touch, so the difference should be big enough for the light sensor to pick up without too much work. The time between force and light should be approximately 75-150 ms by a rough guesstimate. I'm hoping the sensors aren't going to limit my experiments, but if they are, then I guess I'll have to deal with that later.
Your assumptions are correct - that's what I intend to do. And good to hear that I've managed to make the circuit safe, then I should be able to start experimenting a bit with it soon!
Also, I've written some code for it, but it's entirely untested as I wanted some input on the circuit before trying it out. The limits I've set for what counts as "enough" pressure/light are currently set to half (512), but I intend to calibrate that value later on to reflect the actual values I can expect to read from the input.
const int forceSensorPin = 0; // Force sensitive resistor on A0
const int lightSensorPin = 1; // Light sensitive resistor on A1
const int forceLimit = 512; // The lowest force reading to count as force
const int lightLimit = 512; // The lowest light reading to count as light
int forceInput = -1; // The measured force, 0-1023 (inclusive)
int lightInput = -1; // The measured light, 0-1023 (inclusive)
int forceTime = -1; // The time when force was measured
int lightTime = -1; // The time when light was measured
int latency = -1; // The time delta of the lightTime and forceTime
int avgLatency = -1; // The average latency of all measured cycles
void setup() {
Serial.begin(9600);
}
void loop() {
if (forceTime == -1) { // if force not measured
readForce();
} else if (forceTime != -1 && lightTime == -1) { // if force measured and light not measured
readLight();
calculateLatency();
printLatency();
reset();
}
}
void readForce() {
forceInput = analogRead(forceSensorPin);
if (forceInput >= forceLimit) {
forceTime = millis();
}
}
void readLight() {
lightInput = analogRead(lightSensorPin);
if (lightInput >= lightLimit) {
lightTime = millis();
}
}
void calculateLatency() {
latency = lightTime - forceTime;
if (avgLatency == -1) {
avgLatency = latency;
} else {
avgLatency = ((avgLatency + latency) / 2) + 0.5;
}
}
void printLatency() {
Serial.print("Latency: ");
Serial.println(latency);
Serial.print("Average: ");
Serial.println(avgLatency);
Serial.println();
}
void reset() {
forceInput = -1;
lightInput = -1;
forceTime = -1;
lightTime = -1;
latency = -1;
}