After breaking 2 touchscreens, I am finally able to play with my third screen and start working on my project. I have been building my code from the tftpaint.shield example for my project. I'm trying to design my project so that depending on a button selection, it will take you to another screen. I have been building my functions individually and testing fine. What I need help is getting the touchscreen selection to work in each function. Not sure how to declare this. Here's my code. Please excuse the mess.
[Edit - moderator - please use the 'code' button when submitting code.]
Code: Select all
#include "TFTLCD.h"
#include "TouchScreen.h"
#if not defined USE_ADAFRUIT_SHIELD_PINOUT
#error "For use with the shield, make sure to #define USE_ADAFRUIT_SHIELD_PINOUT in the TFTLCD.h library file"
#endif
// These are the pins for the shield!
#define YP A1 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 7 // can be a digital pin
#define XP 6 // can be a digital pin
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, 0);
void setup(void) {
Serial.begin(9600);
tft.reset();
uint16_t identifier = tft.readRegister(0x0);
if (identifier == 0x9325) {
Serial.println("Found ILI9325");
} else if (identifier == 0x9328) {
Serial.println("Found ILI9328");
} else {
Serial.print("Unknown driver chip ");
Serial.println(identifier, HEX);
while (1);
}
tft.initDisplay();
tft.fillScreen(BLACK);
pinMode(13, OUTPUT);
// selectMotor();
propellerScreen();
//raveScreen();
}
#define MINPRESSURE 10
#define MAXPRESSURE 1000
void loop()
{
#define MINPRESSURE 10
#define MAXPRESSURE 1000
digitalWrite(13, HIGH);
Point p = ts.getPoint();
digitalWrite(13, LOW);
// if you're sharing pins, you'll need to fix the directions of the touchscreen pins!
//pinMode(XP, OUTPUT);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//pinMode(YM, OUTPUT);
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { // display x & y points of touchscreen
Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print("\tPressure = "); Serial.println(p.z);
}
if (p.y > 330 && p.y < 650 && p.x > 250 && p.x < 380){
Serial.println("Rave");
}
if (p.y > 330 && p.y < 650 && p.x > 490 && p.x < 605){
Serial.println("propeller");
}
// selectMotor();
// raveScreen();
// propellerScreen();
}
void selectMotor(){ // first page selection
tft.fillScreen(BLACK);
tft.setCursor(50, 20);
tft.setRotation(3);
tft.setTextSize(2);
tft.setTextColor(YELLOW);
tft.println("Select the motor");
tft.setCursor(40, 38);
tft.println(" you want to test");
tft.fillRect(80, 90, 130, 40, YELLOW);
tft.setTextColor(BLACK);
tft.setCursor(92, 100);
tft.println("PROPELLER");
tft.fillRect(80, 160, 130, 40, YELLOW);
tft.setCursor(99, 170);
tft.println(" RAVE");
}
void raveScreen(){ //rave motor screen
tft.fillScreen(BLACK);
tft.setRotation(3);
tft.setTextSize(1);
tft.setTextColor(YELLOW);
tft.fillCircle(35, 40, 15, RED); // return switch circle
tft.fillCircle(280, 40, 15, RED); // on off switch circle
tft.setCursor(27, 37);
tft.println("RET");
tft.setCursor(272, 37);
tft.println("OFF");
tft.fillRoundRect(10, 120, 70, 40, 10, CYAN); // first box
tft.fillRoundRect(120, 120, 70, 40, 10, CYAN); // second
tft.fillRoundRect(230, 120, 70, 40, 10, CYAN); // third
tft.fillRoundRect(60, 190, 70, 40, 10, CYAN); // fourth
tft.fillRoundRect(182, 190, 70, 40, 10, CYAN); // fifth
tft.setCursor(20, 128);
tft.setTextColor(BLACK);
tft.println(" CHANGE\n\n DIRECTION");
tft.setCursor(123, 130);
tft.println("DECREASE BY");
tft.setCursor(149, 141);
tft.println("5 %");
tft.setCursor(233, 130);
tft.println("INCREASE BY");
tft.setCursor(258, 141);
tft.println("5 %");
tft.setCursor(88, 205);
tft.print("25 %");
tft.setCursor(208, 205);
tft.print("50 %");
tft.setTextSize(2);
tft.setTextColor(CYAN);
tft.setCursor(90, 32);
tft.println("PARTY MOTOR");
tft.setCursor(10, 80);
tft.print("Current Speed: ");
}
void propellerScreen(){ // propeller motor screen
tft.fillScreen(BLACK);
tft.setRotation(3);
tft.fillCircle(35, 40, 15, RED); // retrn switch
tft.fillCircle(280, 40, 15, RED); // on off switch
tft.setTextColor(YELLOW);
tft.setTextSize(1);
tft.setCursor(27, 37);
tft.println("RET");
tft.setCursor(272, 37);
tft.println("OFF");
tft.fillRoundRect(10, 120, 70, 40, 10, MAGENTA); // first box
tft.fillRoundRect(120, 120, 70, 40, 10, MAGENTA); // second
tft.fillRoundRect(230, 120, 70, 40, 10, MAGENTA); // third
tft.fillRoundRect(60, 190, 70, 40, 10, MAGENTA); // fourth
tft.fillRoundRect(182, 190, 70, 40, 10, MAGENTA); // fifth
tft.setCursor(20, 128);
tft.println(" CHANGE\n\n DIRECTION");
tft.setCursor(123, 130);
tft.println("DECREASE BY");
tft.setCursor(149, 141);
tft.println("5 %");
tft.setCursor(233, 130);
tft.println("INCREASE BY");
tft.setCursor(258, 141);
tft.println("5 %");
tft.setCursor(88, 205);
tft.println("25 %");
tft.setCursor(208, 205);
tft.setTextColor(YELLOW);
tft.println("50 %");
tft.setTextSize(2);
tft.setTextColor(MAGENTA);
tft.setCursor(70, 30);
tft.println("PROPELLER MOTOR");
tft.setCursor(10, 80);
tft.print("Current Speed: ");
}