如何解决读取 4 线电阻式触摸屏的坐标
我用 Arduino Mega2560 连接了我的 4 线触摸屏。我使用的指南来自:https://www.instructables.com/Resistive-Touch-Screen-on-the-DP32/。 但是我从触摸屏输出中获得的坐标还不够准确。当我沿着 X 轴前进时,Y 轴的坐标也在变化。只是一点点,但随着距离的增加,差异越来越大。
所以我的主要问题是,我无法正确校准我的 4 线触摸屏。
我从指南第 7 步的计算中获得了 a 和 b 的值。
如有任何问题,这是我的代码:
#define Yin A0
#define Yout A1
#define Xin A2
#define Xout A3
#define a_1 0.02281
#define b_1 198.2
#define a_3 -0.01455
#define b_3 704.2
#define a_4 -0.01707
#define b_4 83.41
#define a_6 0.01996
#define b_6 829.0
#define C_x 22.81
#define C_y 30.41
int readX;
int readY;
float X;
float Y;
float correctX(int measuredX,int measuredY);
float correctY(int measuredX,int measuredY);
void setup()
{
pinMode(Xin,INPUT);
pinMode(Yin,INPUT);
pinMode(Xout,INPUT);
pinMode(Yout,INPUT);
Serial.begin(9600);
}
void loop()
{
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Read X
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Set Y to a gradient
pinMode(Yin,OUTPUT);
pinMode(Yout,OUTPUT);
digitalWrite(Yin,LOW);
digitalWrite(Yout,HIGH);
delay(5); // Pause to allow lines to power up
// Read and store X
readX = analogRead(Xin);
// Reset Y
digitalWrite(Yout,LOW);
delay(5); // Pause to allow lines to power down
pinMode(Yin,INPUT);
pinMode(Yout,INPUT);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Read Y
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Set X to a gradient
pinMode(Xin,OUTPUT);
pinMode(Xout,OUTPUT);
digitalWrite(Xin,LOW);
digitalWrite(Xout,HIGH);
delay(5); // Pause to allow lines to power up
// Read and store Y
readY = analogRead(Yin);
// Reset X
digitalWrite(Xout,LOW);
delay(5); // Pause to allow lines to power down
pinMode(Xin,INPUT);
pinMode(Xout,INPUT);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Correct X
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X = correctX(readX,readY);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Correct Y
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Y = correctY(readX,readY);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Output our values
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Serial.print(X);
Serial.print("\t");
Serial.println(Y);
delay(250); // Debounce
}
}
float correctX(int measuredX,int measuredY)
{
float correctedX;
float temp;
temp = (a_4 * measuredY) + b_4;
correctedX = measuredX - temp;
temp = (a_6 * measuredY) + b_6;
correctedX = correctedX / temp;
correctedX = correctedX * C_x;
return correctedX;
}
float correctY(int measuredX,int measuredY)
{
float correctedY;
float temp;
temp = (a_1 * measuredX) + b_1;
correctedY = measuredY - temp;
temp = (a_3 * measuredX) + b_3;
correctedY = correctedY / temp;
correctedY = correctedY * C_y;
return correctedY;
}
如果有人能进一步帮助我,将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。