You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.3 KiB

4 years ago
  1. #include <Adafruit_GFX.h> // Core graphics library
  2. #include <MCUFRIEND_kbv.h> // Hardware-specific library
  3. MCUFRIEND_kbv tft;
  4. #include <Fonts/FreeSans9pt7b.h>
  5. #include <Fonts/FreeSans12pt7b.h>
  6. #include <Fonts/FreeSerif12pt7b.h>
  7. #include <FreeDefaultFonts.h>
  8. #define BLACK 0x0000
  9. #define RED 0xF800
  10. #define GREEN 0x07E0
  11. #define WHITE 0xFFFF
  12. #define GREY 0x8410
  13. int brightnessread = 0;
  14. int cat = 0;
  15. int resultsread1 = 0;
  16. void setup(void)
  17. {
  18. Serial.begin(9600);
  19. uint16_t ID = tft.readID();
  20. if (ID == 0xD3) ID = 0x9481;
  21. tft.begin(ID);
  22. tft.setRotation(1);
  23. tft.WriteCmdData(0x51, 0x00);
  24. //resultsread1 = tft.readReg(0x52);
  25. //writeData(0x51);
  26. }
  27. void loop(void)
  28. {
  29. //brightnessread = readReg32(cat);
  30. Serial.println(resultsread1,BIN);
  31. tft.fillScreen(BLACK);
  32. tft.WriteCmdData(0x51, 0x0000);
  33. showmsgXY(20, 10, 1, NULL, "System x1");
  34. showmsgXY(20, 24, 2, NULL, "System x2");
  35. showmsgXY(20, 60, 1, &FreeSans9pt7b, "FreeSans9pt7b");
  36. showmsgXY(20, 80, 1, &FreeSans12pt7b, "FreeSans12pt7b");
  37. showmsgXY(20, 100, 1, &FreeSerif12pt7b, "FreeSerif12pt7b");
  38. showmsgXY(20, 120, 1, &FreeSmallFont, "FreeSmallFont");
  39. showmsgXY(5, 180, 1, &FreeSevenSegNumFont, "01234");
  40. showmsgXY(5, 190, 1, NULL, "System Font is drawn from topline");
  41. tft.setTextColor(RED, GREY);
  42. tft.setTextSize(2);
  43. tft.setCursor(0, 220);
  44. tft.print("7x5 can overwrite");
  45. delay(1000);
  46. tft.setCursor(0, 220);
  47. tft.print("if background set");
  48. delay(1000);
  49. showmsgXY(5, 260, 1, &FreeSans9pt7b, "Free Fonts from baseline");
  50. showmsgXY(5, 285, 1, &FreeSans9pt7b, "Free Fonts transparent");
  51. delay(1000);
  52. showmsgXY(5, 285, 1, &FreeSans9pt7b, "Free Fonts XXX");
  53. delay(1000);
  54. showmsgXY(5, 310, 1, &FreeSans9pt7b, "erase backgnd with fillRect()");
  55. delay(10000);
  56. }
  57. void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg)
  58. {
  59. int16_t x1, y1;
  60. uint16_t wid, ht;
  61. tft.drawFastHLine(0, y, tft.width(), WHITE);
  62. tft.setFont(f);
  63. tft.setCursor(x, y);
  64. tft.setTextColor(GREEN);
  65. tft.setTextSize(sz);
  66. tft.print(msg);
  67. delay(1000);
  68. }
  69. uint32_t readReg32(uint16_t reg)
  70. {
  71. uint16_t h = tft.readReg(reg, 0);
  72. uint16_t l = tft.readReg(reg, 1);
  73. return ((uint32_t) h << 16) | (l);
  74. }