Advertisement
pleasedontcode

TFT Interaction rev_01

Oct 6th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: TFT Interaction
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-10-06 23:25:22
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* #include <MCUFRIEND_kbv.h>  #include */
  21.     /* <Adafruit_GFX.h>  #include <TouchScreen.h> */
  22.     /* MCUFRIEND_kbv tft; */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <MCUFRIEND_kbv.h>  // Include the MCUFRIEND_kbv library for TFT display
  27. #include <Adafruit_GFX.h>   // Include the Adafruit GFX library for graphics
  28. #include <TouchScreen.h>     // Include the TouchScreen library for touch functionality
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF ANALOG INPUT PINS *****/
  35. const uint8_t p1_Potentiometer_Vout_PIN_A0 = A0;
  36.  
  37. // Instantiate the TFT display object
  38. MCUFRIEND_kbv tft;
  39.  
  40. // Define touch screen pins
  41. #define YP A1  // Y+ pin
  42. #define XM A2  // X- pin
  43. #define YM 7   // Y- pin
  44. #define XP 6   // X+ pin
  45.  
  46. // Instantiate the touch screen object
  47. TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
  48.  
  49. // Setup function
  50. void setup(void)
  51. {
  52.     // Initialize the TFT display
  53.     tft.begin();
  54.     tft.setRotation(1); // Set the rotation of the display
  55.     tft.fillScreen(TFT_WHITE); // Fill the screen with white color
  56.  
  57.     // Set the potentiometer pin as input
  58.     pinMode(p1_Potentiometer_Vout_PIN_A0, INPUT);
  59. }
  60.  
  61. // Main loop function
  62. void loop(void)
  63. {
  64.     // Read the touch screen
  65.     TSPoint p = ts.getPoint();
  66.  
  67.     // If the screen is touched
  68.     if (p.z > ts.pressureThreshhold) {
  69.         // Draw a point where the screen is touched
  70.         tft.fillCircle(p.x, p.y, 5, TFT_RED); // Draw a red circle at the touch point
  71.     }
  72.  
  73.     // Read the potentiometer value
  74.     int potValue = analogRead(p1_Potentiometer_Vout_PIN_A0);
  75.    
  76.     // You can add code here to use the potentiometer value
  77. }
  78.  
  79. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement