![](/media/cache/group/Display_Nokia_Insper_v01.jpg.50x50_q85.jpg)
Testando função Touch Display TFT
Dependencies: mbed TouchScreen_kbv_mbed MCUFRIEND_kbv_R299 GLUE_STUFF_kbv ADA_GFX_kbv_R1107
TFT_TouchShield.cpp@1:e55610b3999a, 2021-04-30 (annotated)
- Committer:
- henriquer
- Date:
- Fri Apr 30 11:38:26 2021 +0000
- Revision:
- 1:e55610b3999a
- Parent:
- 0:063c3eaefd81
- Child:
- 2:d8d564f86bc8
Teste com botoes Touch
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
henriquer | 1:e55610b3999a | 1 | // ****** Henrique ****** 29/04/21 |
henriquer | 1:e55610b3999a | 2 | // Teste com botões Touch |
henriquer | 1:e55610b3999a | 3 | // |
henriquer | 1:e55610b3999a | 4 | // ************** Display TFT- ILI9341 Versão V 1************** \\ |
davidprentice | 0:063c3eaefd81 | 5 | |
davidprentice | 0:063c3eaefd81 | 6 | |
henriquer | 1:e55610b3999a | 7 | #include "mbed.h" |
henriquer | 1:e55610b3999a | 8 | #include "Arduino.h" |
davidprentice | 0:063c3eaefd81 | 9 | #include <MCUFRIEND_kbv.h> |
henriquer | 1:e55610b3999a | 10 | MCUFRIEND_kbv tft; |
davidprentice | 0:063c3eaefd81 | 11 | #include "TouchScreen_kbv_mbed.h" |
davidprentice | 0:063c3eaefd81 | 12 | |
henriquer | 1:e55610b3999a | 13 | |
henriquer | 1:e55610b3999a | 14 | const int TS_LEFT=150,TS_RT=120,TS_TOP=920,TS_BOT=940; |
davidprentice | 0:063c3eaefd81 | 15 | const PinName XP = D7, YP = A2, XM = A1, YM = D6; //next common configuration |
davidprentice | 0:063c3eaefd81 | 16 | DigitalInOut YPout(YP); |
henriquer | 1:e55610b3999a | 17 | |
davidprentice | 0:063c3eaefd81 | 18 | DigitalInOut XMout(XM); |
henriquer | 1:e55610b3999a | 19 | |
henriquer | 1:e55610b3999a | 20 | |
henriquer | 1:e55610b3999a | 21 | Serial pc(USBTX, USBRX); |
henriquer | 1:e55610b3999a | 22 | |
davidprentice | 0:063c3eaefd81 | 23 | long map(long x, long in_min, long in_max, long out_min, long out_max) |
davidprentice | 0:063c3eaefd81 | 24 | { |
davidprentice | 0:063c3eaefd81 | 25 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
davidprentice | 0:063c3eaefd81 | 26 | } |
henriquer | 1:e55610b3999a | 27 | |
henriquer | 1:e55610b3999a | 28 | |
davidprentice | 0:063c3eaefd81 | 29 | TouchScreen_kbv ts = TouchScreen_kbv(XP, YP, XM, YM, 300); |
davidprentice | 0:063c3eaefd81 | 30 | TSPoint_kbv tp; |
davidprentice | 0:063c3eaefd81 | 31 | |
henriquer | 1:e55610b3999a | 32 | #define MINPRESSURE 10 |
davidprentice | 0:063c3eaefd81 | 33 | #define MAXPRESSURE 1000 |
davidprentice | 0:063c3eaefd81 | 34 | |
henriquer | 1:e55610b3999a | 35 | |
davidprentice | 0:063c3eaefd81 | 36 | |
henriquer | 1:e55610b3999a | 37 | uint8_t Orientation = 1; // Orientção do Display |
henriquer | 1:e55610b3999a | 38 | |
henriquer | 1:e55610b3999a | 39 | // Tabela de valores de cores : |
davidprentice | 0:063c3eaefd81 | 40 | #define BLACK 0x0000 |
davidprentice | 0:063c3eaefd81 | 41 | #define BLUE 0x001F |
davidprentice | 0:063c3eaefd81 | 42 | #define RED 0xF800 |
davidprentice | 0:063c3eaefd81 | 43 | #define GREEN 0x07E0 |
davidprentice | 0:063c3eaefd81 | 44 | #define CYAN 0x07FF |
davidprentice | 0:063c3eaefd81 | 45 | #define MAGENTA 0xF81F |
davidprentice | 0:063c3eaefd81 | 46 | #define YELLOW 0xFFE0 |
davidprentice | 0:063c3eaefd81 | 47 | #define WHITE 0xFFFF |
davidprentice | 0:063c3eaefd81 | 48 | |
henriquer | 1:e55610b3999a | 49 | bool botu_1 =0; |
davidprentice | 0:063c3eaefd81 | 50 | |
davidprentice | 0:063c3eaefd81 | 51 | void show_tft(void) |
davidprentice | 0:063c3eaefd81 | 52 | { |
henriquer | 1:e55610b3999a | 53 | |
davidprentice | 0:063c3eaefd81 | 54 | tft.setTextSize(2); |
henriquer | 1:e55610b3999a | 55 | |
henriquer | 1:e55610b3999a | 56 | |
henriquer | 1:e55610b3999a | 57 | tft.setTextColor(MAGENTA,BLACK); |
henriquer | 1:e55610b3999a | 58 | |
henriquer | 1:e55610b3999a | 59 | |
davidprentice | 0:063c3eaefd81 | 60 | while (1) { |
davidprentice | 0:063c3eaefd81 | 61 | tp = ts.getPoint(); |
davidprentice | 0:063c3eaefd81 | 62 | YPout.output(); |
davidprentice | 0:063c3eaefd81 | 63 | XMout.output(); |
henriquer | 1:e55610b3999a | 64 | |
henriquer | 1:e55610b3999a | 65 | if (tp.z < MINPRESSURE && tp.z > MAXPRESSURE) |
henriquer | 1:e55610b3999a | 66 | |
henriquer | 1:e55610b3999a | 67 | tp.x = tft.width() - (map(tp.x, TS_RT, TS_LEFT, tft.width(), 0)); |
henriquer | 1:e55610b3999a | 68 | tp.y = tft.height() - (map(tp.y, TS_BOT, TS_TOP, tft.height(), 0)); |
henriquer | 1:e55610b3999a | 69 | |
henriquer | 1:e55610b3999a | 70 | |
henriquer | 1:e55610b3999a | 71 | |
henriquer | 1:e55610b3999a | 72 | if (tp.x>700&tp.x<800) { |
henriquer | 1:e55610b3999a | 73 | |
henriquer | 1:e55610b3999a | 74 | |
henriquer | 1:e55610b3999a | 75 | tft.setCursor(15, 200); |
henriquer | 1:e55610b3999a | 76 | tft.printf("Button 1"); |
henriquer | 1:e55610b3999a | 77 | |
henriquer | 1:e55610b3999a | 78 | } |
henriquer | 1:e55610b3999a | 79 | |
henriquer | 1:e55610b3999a | 80 | if (tp.x>776&tp.x<845) { |
henriquer | 1:e55610b3999a | 81 | |
henriquer | 1:e55610b3999a | 82 | |
henriquer | 1:e55610b3999a | 83 | tft.setCursor(15, 200); |
henriquer | 1:e55610b3999a | 84 | tft.printf("Button 2"); |
henriquer | 1:e55610b3999a | 85 | |
henriquer | 1:e55610b3999a | 86 | } |
henriquer | 1:e55610b3999a | 87 | |
davidprentice | 0:063c3eaefd81 | 88 | tft.setCursor(0, (tft.height() * 3) / 4); |
henriquer | 1:e55610b3999a | 89 | |
henriquer | 1:e55610b3999a | 90 | tft.printf("tp.x=%d ", tp.x); |
henriquer | 1:e55610b3999a | 91 | |
davidprentice | 0:063c3eaefd81 | 92 | } |
davidprentice | 0:063c3eaefd81 | 93 | } |
davidprentice | 0:063c3eaefd81 | 94 | |
davidprentice | 0:063c3eaefd81 | 95 | |
henriquer | 1:e55610b3999a | 96 | |
henriquer | 1:e55610b3999a | 97 | void bot_1 () |
henriquer | 1:e55610b3999a | 98 | { |
henriquer | 1:e55610b3999a | 99 | |
henriquer | 1:e55610b3999a | 100 | |
henriquer | 1:e55610b3999a | 101 | tft.setCursor(40, 50); |
henriquer | 1:e55610b3999a | 102 | tft.drawRoundRect(5, 15, 200, 50, 5, WHITE); |
henriquer | 1:e55610b3999a | 103 | tft.setTextColor(BLUE); |
henriquer | 1:e55610b3999a | 104 | tft.setTextSize(3); |
henriquer | 1:e55610b3999a | 105 | tft.setCursor(15, 30); |
henriquer | 1:e55610b3999a | 106 | tft.println("Button 1"); |
henriquer | 1:e55610b3999a | 107 | |
henriquer | 1:e55610b3999a | 108 | |
henriquer | 1:e55610b3999a | 109 | |
henriquer | 1:e55610b3999a | 110 | |
henriquer | 1:e55610b3999a | 111 | tft.drawRoundRect(5, 70, 200, 50, 5, WHITE); |
henriquer | 1:e55610b3999a | 112 | tft.setTextColor(BLUE); |
henriquer | 1:e55610b3999a | 113 | tft.setTextSize(3); |
henriquer | 1:e55610b3999a | 114 | tft.setCursor(15,85); |
henriquer | 1:e55610b3999a | 115 | tft.println("Button 2"); |
henriquer | 1:e55610b3999a | 116 | |
henriquer | 1:e55610b3999a | 117 | |
henriquer | 1:e55610b3999a | 118 | |
henriquer | 1:e55610b3999a | 119 | } |
henriquer | 1:e55610b3999a | 120 | |
davidprentice | 0:063c3eaefd81 | 121 | void setup(void) |
davidprentice | 0:063c3eaefd81 | 122 | { |
davidprentice | 0:063c3eaefd81 | 123 | |
davidprentice | 0:063c3eaefd81 | 124 | tft.reset(); |
henriquer | 1:e55610b3999a | 125 | tft.begin(); |
davidprentice | 0:063c3eaefd81 | 126 | tft.setRotation(Orientation); |
davidprentice | 0:063c3eaefd81 | 127 | tft.fillScreen(BLACK); |
henriquer | 1:e55610b3999a | 128 | bot_1(); |
davidprentice | 0:063c3eaefd81 | 129 | show_tft(); |
davidprentice | 0:063c3eaefd81 | 130 | |
davidprentice | 0:063c3eaefd81 | 131 | |
davidprentice | 0:063c3eaefd81 | 132 | delay(1000); |
davidprentice | 0:063c3eaefd81 | 133 | } |
davidprentice | 0:063c3eaefd81 | 134 | |
davidprentice | 0:063c3eaefd81 | 135 | void loop() |
davidprentice | 0:063c3eaefd81 | 136 | { |
davidprentice | 0:063c3eaefd81 | 137 | |
davidprentice | 0:063c3eaefd81 | 138 | } |
davidprentice | 0:063c3eaefd81 | 139 |