Hello all,
I need some help with my code.
Basically I have to read out a touchscreen and detect wrong measurements.
When the values of coords are above 100 and 150 the measurement is correct and the value of the touchscreen is accepted. (Thus, the if-condition is fullfilled)
However, when it’s not above those values, it has to just remember the previous values and do nothing actually.
My code does work and I get correct values.
However when I remove the delay and the values are under the minimum (i.e. measurement error), the value I get is not the previous one (it’s always around -0,07, no matter what previous one is).
It works good when the delay is above 100ms…
Can anyone explain to me why this is? Or is the code correct and does it have to do with the serial.print?
Thanks!
#include <TouchScreen.h>
TouchScreen ts(0,1,2,3,4);
int coords[2];
double coords_double[2];
void setup()
{
Serial.begin(38400);
}
void loop()
{
ts.read(coords);
if(coords[0] > 100 && coords[1] > 150) {
coords_double[0] = map((double)coords[0], 153, 793, -108, 108); //(double) map(coords[0], 124, 783, -108, 108);
coords_double[0] = coords_double[0]/1000;
coords_double[1] = map((double)coords[1], 208, 799, -84, 84); //(double) map(coords[0], 124, 783, -108, 108);
coords_double[1] = coords_double[1]/1000;
}
else {
}
Serial.print(coords_double[0]);
Serial.print(",");
Serial.println(coords_double[1]);
delay(1000);
}