Advertisement
balatech

Basic Touch

Jan 2nd, 2025 (edited)
70
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.73 KB | Source Code | 0 0
  1. #include <Wire.h>
  2. #include <PCA9557.h> //PCA9557-arduino v1.0.0
  3. #include <TAMC_GT911.h> //TAMC_GT911 by TAMC v 1.0.9
  4. #include <LovyanGFX.hpp> //LovyanGFX v1.2.0
  5. #include "gfx_conf.h" // part of this build
  6.  
  7. #define TOUCH_SDA  19
  8. #define TOUCH_SCL  20
  9. #define TOUCH_INT -1
  10. #define TOUCH_RST -1
  11. #define TOUCH_WIDTH  800
  12. #define TOUCH_HEIGHT 480
  13.  
  14. TAMC_GT911 tp = TAMC_GT911(TOUCH_SDA, TOUCH_SCL, TOUCH_INT, TOUCH_RST, TOUCH_WIDTH, TOUCH_HEIGHT);
  15. PCA9557 Out;
  16.  
  17.  
  18.  
  19. void setup() {
  20.   tp.begin(0x5D); // sets up the touch instance
  21.   tp.setRotation(ROTATION_INVERTED); // set it to landscape, 0,0 top left with usb on left
  22.  
  23.  
  24.   Wire.begin(19, 20); // talk to the IO Expander chip PCA9557
  25.   // now we're going to 'reset' the touch panel.
  26.   Out.reset();
  27.   Out.setMode(IO_OUTPUT);
  28.   Out.setState(IO0, IO_LOW); // takes the reset pin of the GT_911 low
  29.   Out.setState(IO1, IO_LOW); // takes the ??INTE (poss interrupt) pin low
  30.   delay(20);                 // wait for timings
  31.   Out.setState(IO0, IO_HIGH);// release reset pin
  32.   delay(100);                // wait for timing again
  33.   Out.setMode(IO1, IO_INPUT);// set the intE pin as input again
  34.   delay(2000);
  35.  
  36.   lcd.begin(); // start the lcd
  37.   lcd.fillScreen(0x6ecb); // set it to a colour of choice
  38.   lcd.setTextFont(&fonts::FreeMonoBold9pt7b);
  39.   lcd.setTextSize(2);
  40.   lcd.setTextColor(TFT_BLUE,TFT_WHITE);
  41. }
  42.  
  43. void loop() {
  44.   tp.read();
  45.    if (tp.isTouched){  
  46.     for (int i=0; i<tp.touches; i++){  
  47.         Serial.printf(" Touch point %i, X =%i, Y =%i \n\r",i,tp.points[i].x, tp.points[i].y);
  48.         lcd.fillCircle(tp.points[i].x, tp.points[i].y, 10, TFT_WHITE);
  49.        
  50.         lcd.setCursor(tp.points[i].x,tp.points[i].y);
  51.         lcd.print(String(i));  
  52.     }
  53.    }
  54.  
  55. }
  56.  
Advertisement
Comments
  • balatech
    18 days
    # text 0.09 KB | 0 0
    1. This is the main .ino file to test touch functions. Ensure you also download the gfx_conf.h file!
Add Comment
Please, Sign In to add comment
Advertisement