I have this display:
Interface: 4 wire SPI
Screen: Resistive Touch
Controller: Arduino Uno
I am using the RA8875.h library: GitHub - sumotoy/RA8875: A library for RAiO RA8875 display driver for Teensy3.x or LC/Arduino's/Energia/Spark
The library is for an internal resistive touchscreen controller.
the RA8875.h library works fine for drawing. However, I can't get ANY of the resistive touch examples to run.
For instance, this example does not even compile:
#include <SPI.h>
#include <RA8875.h>
#define RA8875_INT 2 //any pin
#define RA8875_CS 10 //see below...
#define RA8875_RESET 9//any pin or nothing!
RA8875 tft = RA8875(RA8875_CS,RA8875_RESET);//Teensy3/arduino's
uint16_t tx, ty;
void interface(){
tft.fillRect(10,10,40,40,RA8875_WHITE);
tft.fillRect(10+(40*1)+(10*1),10,40,40,RA8875_BLUE);
tft.fillRect(10+(40*2)+(10*2),10,40,40,RA8875_RED);
tft.fillRect(10+(40*3)+(10*3),10,40,40,RA8875_GREEN);
tft.fillRect(10+(40*4)+(10*4),10,40,40,RA8875_CYAN);
tft.fillRect(10+(40*5)+(10*5),10,40,40,RA8875_MAGENTA);
tft.fillRect(10+(40*6)+(10*6),10,40,40,RA8875_YELLOW);
tft.drawRect(10+(40*7)+(10*7),10,40,40,RA8875_WHITE);
}
void setup()
{
Serial.begin(9600);
//while (!Serial) {;}
Serial.println("RA8875 start");
tft.begin(RA8875_480x272);//initialize library
tft.touchBegin(RA8875_INT);//enable Touch support!
interface();
}
uint16_t choosenColor = 0;
void loop()
{
if (tft.touchDetect()){//easy!
tft.touchReadPixel(&tx, &ty);//read directly in pixel!
if (ty >= 0 && ty <= 55){ //interface area
if ((tx > 10 && tx < (10+40))){
choosenColor = RA8875_WHITE;
interface();
tft.fillRect(10,10,40,40,RA8875_BLACK);
tft.fillCircle(tft.width()-10,10,5,choosenColor);
}
else if ((tx > 10+(40*1)+(10*1) && tx < 10+(40*2)+(10*1))){
choosenColor = RA8875_BLUE;
interface();
tft.fillRect(10+(40*1)+(10*1),10,40,40,RA8875_BLACK);
tft.fillCircle(tft.width()-10,10,5,choosenColor);
}
else if ((tx > 10+(40*2)+(10*2) && tx < 10+(40*3)+(10*2))){
choosenColor = RA8875_RED;
interface();
tft.fillRect(10+(40*2)+(10*2),10,40,40,RA8875_BLACK);
tft.fillCircle(tft.width()-10,10,5,choosenColor);
}
else if ((tx > 10+(40*3)+(10*3) && tx < 10+(40*4)+(10*3))){
choosenColor = RA8875_GREEN;
interface();
tft.fillRect(10+(40*3)+(10*3),10,40,40,RA8875_BLACK);
tft.fillCircle(tft.width()-10,10,5,choosenColor);
}
else if ((tx > 10+(40*4)+(10*4) && tx < 10+(40*5)+(10*4))){
choosenColor = RA8875_CYAN;
interface();
tft.fillRect(10+(40*4)+(10*4),10,40,40,RA8875_BLACK);
tft.fillCircle(tft.width()-10,10,5,choosenColor);
}
else if ((tx > 10+(40*5)+(10*5) && tx < 10+(40*6)+(10*5))){
choosenColor = RA8875_MAGENTA;
interface();
tft.fillRect(10+(40*5)+(10*5),10,40,40,RA8875_BLACK);
tft.fillCircle(tft.width()-10,10,5,choosenColor);
}
else if ((tx > 10+(40*6)+(10*6) && tx < 10+(40*7)+(10*6))){
choosenColor = RA8875_YELLOW;
interface();
tft.fillRect(10+(40*6)+(10*6),10,40,40,RA8875_BLACK);
tft.fillCircle(tft.width()-10,10,5,choosenColor);
}
else if ((tx > 10+(40*7)+(10*7) && tx < 10+(40*8)+(10*7))){
choosenColor = 0;
interface();
tft.fillRect(0,52,tft.width()-1,tft.height()-53,RA8875_BLACK);
tft.fillCircle(tft.width()-10,10,5,RA8875_BLACK);
}
} else { //paint
//if (choosenColor != 0) tft.fillCircle(tx,ty,1,choosenColor);
if (choosenColor != 0) tft.drawPixel(tx,ty,choosenColor);
}
}
}
It compiles but only draws, no touchscreen, if you make a few changes:
tft.touchBegin(RA8875_INT); to tft.touchBegin();
tft.touchDetect() to tft.touched
Is there a working resistive touch example I can look at?