I don't know if this code is on the right track to make the touchscreen work.
Code: Select all
//NintendoScreen
#define YP A7
#define XM A8
#define YM A12
#define XP A13
int readtouchX;
int readtouchY;
int fxTogOn = 0;
int fxTogOff = 1;
unsigned long readTime;
unsigned long prevReadTime;
unsigned long readTimeTwo;
unsigned long prevReadTimeTwo;
int getSmooth(int pin){
int vals[10]; //array that stores 10 readings.
for(int i = 0; i < 10; i++){
vals[i] = analogRead(pin); //takes 10 readings.
}
float smooth = (vals[0] + vals[1] + vals[2] + vals[3] + vals[4] + vals[5] + vals[6] + vals[7] + vals[8] + vals[9]) / 10;
return smooth;
}
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Code: Select all
//NDS_TOUCH
//limit reads to 5ms
TSPoint p = ts.getPoint();
readTime = millis();
//readtouchX = readtouchX();
//readtouchY = Touchscreen();
if ((readtouchX < 900) && (readtouchY < 900)){
if(readTime - prevReadTime > 16){
if (p.z > ts.pressureThreshhold) {
Serial.print("X = ");
Serial.print(p.x);
Serial.print("\tY = ");
Serial.print(p.y);
Serial.print("\tPressure = ");
Serial.println(p.z);
fxTogOn = 1;
fxTogOff = 0;
prevReadTime = readTime;
}
}else{
if (abs(fxTogOn - fxTogOff) > 0){
Serial.print("postTog: ");
Serial.print(0);
Serial.print(" ");
Serial.println(0);
fxTogOff = fxTogOn;
}
}
delay(100);
}