Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #include <Adafruit_GFX.h> // Core graphics library
  2. #include <MCUFRIEND_kbv.h> // Hardware-specific library
  3. MCUFRIEND_kbv tft;
  4. #include <stdint.h>
  5. #include "TouchScreen.h"
  6. #include "bitmap_RGB.h"
  7.  
  8. #include <Fonts/FreeSans9pt7b.h>
  9. #include <Fonts/FreeSans12pt7b.h>
  10.  
  11. #define YP A2
  12. #define XM A3
  13. #define YM 8
  14. #define XP 9
  15. #define LCD_CS A3
  16. #define LCD_CD A2
  17. #define LCD_WR A1
  18. #define LCD_RD A0
  19.  
  20. #define LCD_RESET A4
  21. #define BLACK 0x0000
  22. #define BLUE 0x001F
  23. #define RED 0xF800
  24. #define GREEN 0x07E0
  25. #define CYAN 0x07FF
  26. #define MAGENTA 0xF81F
  27. #define YELLOW 0xFFE0
  28. #define WHITE 0xFFFF
  29.  
  30. TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
  31. bool click = false;
  32. float timeSinceClick = 0;
  33. int currentScreen = -1;
  34.  
  35. void setup(void) {
  36. Serial.begin(9600);
  37. resetScreen();
  38. }
  39.  
  40. void resetScreen(){
  41. tft.reset();
  42. tft.begin(0x9341);
  43. tft.setRotation(3);
  44. tft.fillScreen(BLACK);
  45. }
  46.  
  47. void loop(void) {
  48. checkClick();
  49. delay(50);
  50. if(click){
  51. timeSinceClick += 50;
  52. if(timeSinceClick > 5000){
  53. click = false;
  54. timeSinceClick = 0;
  55. drawMessage();
  56. }
  57. } else if(currentScreen != 0){
  58. drawMessage();
  59. }
  60. }
  61.  
  62. void checkClick(void) {
  63. TSPoint p = ts.getPoint();
  64. pinMode(YP, OUTPUT); //restore the TFT control pins
  65. pinMode(XM, OUTPUT);
  66. if (p.z >= 0.01) {
  67. if(click){
  68. sendMessage();
  69. } else{
  70. if(currentScreen != 1) clicked();
  71. click = true;
  72. }
  73. }
  74. }
  75.  
  76. void clicked(void){
  77. //resetScreen();
  78. Serial.println("Yeah");
  79. currentScreen = 1;
  80. tft.fillScreen(BLACK);
  81. tft.drawRGBBitmap(128, 88, heart, 64, 64);
  82. }
  83.  
  84. void sendMessage(void){
  85. tft.fillScreen(BLACK);
  86. currentScreen = 2;
  87. click = false;
  88. timeSinceClick = 0;
  89. tft.setFont(&FreeSans9pt7b);
  90. tft.setCursor(120, 120);
  91. tft.setTextColor(WHITE);
  92. tft.setTextSize(1);
  93. tft.print("Sending...");
  94. delay(3000);
  95. drawMessage();
  96. }
  97.  
  98. void drawMessage(void){
  99. currentScreen = 0;
  100. tft.fillScreen(BLACK);
  101. tft.setFont(&FreeSans12pt7b);
  102. tft.setCursor(100, 30);
  103. tft.setTextColor(CYAN);
  104. tft.setTextSize(1);
  105. tft.print("Hej Julia :)");
  106. tft.setFont(&FreeSans9pt7b);
  107. tft.setCursor(0, 80);
  108. tft.setTextColor(WHITE);
  109. tft.setTextSize(1);
  110. tft.print("\"This graveyard looks overcrowded. People must be dying to get in there.\"");
  111. tft.drawRGBBitmap(128, 140, heart, 64, 64);
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement