Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed TouchScreen_kbv_mbed MCUFRIEND_kbv_R299 GLUE_STUFF_kbv ADA_GFX_kbv_R1107
TFT_TouchShield.cpp@3:f723a8456215, 2021-05-04 (annotated)
- Committer:
- henriquer
- Date:
- Tue May 04 23:21:21 2021 +0000
- Revision:
- 3:f723a8456215
- Parent:
- 2:d8d564f86bc8
button_tft_v3
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| henriquer | 3:f723a8456215 | 1 | // ****** Henrique ****** 04/05/21 | 
| henriquer | 1:e55610b3999a | 2 | // Teste com botões Touch | 
| henriquer | 1:e55610b3999a | 3 | // | 
| henriquer | 3:f723a8456215 | 4 | // ************** Display TFT- ILI9341 Versão V 3************** \\ | 
| 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" | 
| henriquer | 3:f723a8456215 | 12 | DigitalOut led_1(PB_13); | 
| henriquer | 3:f723a8456215 | 13 | DigitalOut led_2(PB_14); | 
| henriquer | 3:f723a8456215 | 14 | DigitalOut led_3(PB_15); | 
| davidprentice | 0:063c3eaefd81 | 15 | |
| henriquer | 1:e55610b3999a | 16 | |
| henriquer | 1:e55610b3999a | 17 | const int TS_LEFT=150,TS_RT=120,TS_TOP=920,TS_BOT=940; | 
| davidprentice | 0:063c3eaefd81 | 18 | const PinName XP = D7, YP = A2, XM = A1, YM = D6; //next common configuration | 
| davidprentice | 0:063c3eaefd81 | 19 | DigitalInOut YPout(YP); | 
| henriquer | 1:e55610b3999a | 20 | |
| davidprentice | 0:063c3eaefd81 | 21 | DigitalInOut XMout(XM); | 
| henriquer | 1:e55610b3999a | 22 | |
| henriquer | 1:e55610b3999a | 23 | |
| henriquer | 1:e55610b3999a | 24 | Serial pc(USBTX, USBRX); | 
| henriquer | 1:e55610b3999a | 25 | |
| davidprentice | 0:063c3eaefd81 | 26 | long map(long x, long in_min, long in_max, long out_min, long out_max) | 
| davidprentice | 0:063c3eaefd81 | 27 | { | 
| davidprentice | 0:063c3eaefd81 | 28 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; | 
| davidprentice | 0:063c3eaefd81 | 29 | } | 
| henriquer | 1:e55610b3999a | 30 | |
| henriquer | 1:e55610b3999a | 31 | |
| davidprentice | 0:063c3eaefd81 | 32 | TouchScreen_kbv ts = TouchScreen_kbv(XP, YP, XM, YM, 300); | 
| davidprentice | 0:063c3eaefd81 | 33 | TSPoint_kbv tp; | 
| davidprentice | 0:063c3eaefd81 | 34 | |
| henriquer | 1:e55610b3999a | 35 | #define MINPRESSURE 10 | 
| davidprentice | 0:063c3eaefd81 | 36 | #define MAXPRESSURE 1000 | 
| davidprentice | 0:063c3eaefd81 | 37 | |
| henriquer | 1:e55610b3999a | 38 | |
| davidprentice | 0:063c3eaefd81 | 39 | |
| henriquer | 1:e55610b3999a | 40 | uint8_t Orientation = 1; // Orientção do Display | 
| henriquer | 1:e55610b3999a | 41 | |
| henriquer | 1:e55610b3999a | 42 | // Tabela de valores de cores : | 
| davidprentice | 0:063c3eaefd81 | 43 | #define BLACK 0x0000 | 
| davidprentice | 0:063c3eaefd81 | 44 | #define BLUE 0x001F | 
| davidprentice | 0:063c3eaefd81 | 45 | #define RED 0xF800 | 
| davidprentice | 0:063c3eaefd81 | 46 | #define GREEN 0x07E0 | 
| davidprentice | 0:063c3eaefd81 | 47 | #define CYAN 0x07FF | 
| davidprentice | 0:063c3eaefd81 | 48 | #define MAGENTA 0xF81F | 
| davidprentice | 0:063c3eaefd81 | 49 | #define YELLOW 0xFFE0 | 
| davidprentice | 0:063c3eaefd81 | 50 | #define WHITE 0xFFFF | 
| davidprentice | 0:063c3eaefd81 | 51 | |
| henriquer | 1:e55610b3999a | 52 | bool botu_1 =0; | 
| davidprentice | 0:063c3eaefd81 | 53 | |
| davidprentice | 0:063c3eaefd81 | 54 | void show_tft(void) | 
| davidprentice | 0:063c3eaefd81 | 55 | { | 
| henriquer | 1:e55610b3999a | 56 | |
| davidprentice | 0:063c3eaefd81 | 57 | tft.setTextSize(2); | 
| henriquer | 1:e55610b3999a | 58 | |
| henriquer | 1:e55610b3999a | 59 | |
| henriquer | 1:e55610b3999a | 60 | tft.setTextColor(MAGENTA,BLACK); | 
| henriquer | 1:e55610b3999a | 61 | |
| henriquer | 1:e55610b3999a | 62 | |
| davidprentice | 0:063c3eaefd81 | 63 | while (1) { | 
| davidprentice | 0:063c3eaefd81 | 64 | tp = ts.getPoint(); | 
| davidprentice | 0:063c3eaefd81 | 65 | YPout.output(); | 
| davidprentice | 0:063c3eaefd81 | 66 | XMout.output(); | 
| henriquer | 1:e55610b3999a | 67 | |
| henriquer | 1:e55610b3999a | 68 | if (tp.z < MINPRESSURE && tp.z > MAXPRESSURE) | 
| henriquer | 1:e55610b3999a | 69 | |
| henriquer | 3:f723a8456215 | 70 | tp.x = tft.width() - (map(tp.x, TS_RT, TS_LEFT, tft.width(), 0)); | 
| henriquer | 1:e55610b3999a | 71 | tp.y = tft.height() - (map(tp.y, TS_BOT, TS_TOP, tft.height(), 0)); | 
| henriquer | 1:e55610b3999a | 72 | |
| henriquer | 1:e55610b3999a | 73 | |
| henriquer | 1:e55610b3999a | 74 | |
| henriquer | 3:f723a8456215 | 75 | if (tp.x==785) { | 
| henriquer | 3:f723a8456215 | 76 | |
| henriquer | 3:f723a8456215 | 77 | |
| henriquer | 3:f723a8456215 | 78 | |
| henriquer | 3:f723a8456215 | 79 | led_1= 1; | 
| henriquer | 3:f723a8456215 | 80 | led_2 = 0; | 
| henriquer | 3:f723a8456215 | 81 | led_3 = 0; | 
| henriquer | 1:e55610b3999a | 82 | |
| henriquer | 1:e55610b3999a | 83 | |
| henriquer | 3:f723a8456215 | 84 | } | 
| henriquer | 3:f723a8456215 | 85 | |
| henriquer | 3:f723a8456215 | 86 | if (tp.x== 822) { | 
| henriquer | 3:f723a8456215 | 87 | |
| henriquer | 3:f723a8456215 | 88 | |
| henriquer | 3:f723a8456215 | 89 | |
| henriquer | 3:f723a8456215 | 90 | led_2 =1; | 
| henriquer | 3:f723a8456215 | 91 | led_1 =0; | 
| henriquer | 3:f723a8456215 | 92 | led_3 = 0; | 
| henriquer | 1:e55610b3999a | 93 | |
| henriquer | 1:e55610b3999a | 94 | } | 
| henriquer | 1:e55610b3999a | 95 | |
| henriquer | 3:f723a8456215 | 96 | if (tp.x==875) { | 
| henriquer | 3:f723a8456215 | 97 | |
| henriquer | 1:e55610b3999a | 98 | |
| henriquer | 1:e55610b3999a | 99 | |
| henriquer | 3:f723a8456215 | 100 | led_2 =0; | 
| henriquer | 3:f723a8456215 | 101 | led_1 =0; | 
| henriquer | 3:f723a8456215 | 102 | led_3 = 1; | 
| henriquer | 3:f723a8456215 | 103 | |
| henriquer | 3:f723a8456215 | 104 | } | 
| henriquer | 3:f723a8456215 | 105 | |
| henriquer | 3:f723a8456215 | 106 | |
| henriquer | 3:f723a8456215 | 107 | if (tp.x==975) { | 
| henriquer | 3:f723a8456215 | 108 | |
| henriquer | 3:f723a8456215 | 109 | led_2 =1; | 
| henriquer | 3:f723a8456215 | 110 | led_1 =1; | 
| henriquer | 3:f723a8456215 | 111 | led_3 =1; | 
| henriquer | 3:f723a8456215 | 112 | |
| henriquer | 3:f723a8456215 | 113 | } | 
| henriquer | 3:f723a8456215 | 114 | |
| henriquer | 3:f723a8456215 | 115 | if (tp.x==950) { | 
| henriquer | 3:f723a8456215 | 116 | |
| henriquer | 3:f723a8456215 | 117 | led_2 =0; | 
| henriquer | 3:f723a8456215 | 118 | led_1 =0; | 
| henriquer | 3:f723a8456215 | 119 | led_3 =0; | 
| henriquer | 1:e55610b3999a | 120 | |
| henriquer | 1:e55610b3999a | 121 | } | 
| henriquer | 1:e55610b3999a | 122 | |
| henriquer | 3:f723a8456215 | 123 | tft.setCursor(0, (tft.height() * 0) / 4); | 
| henriquer | 3:f723a8456215 | 124 | |
| henriquer | 3:f723a8456215 | 125 | tft.printf(" ", 0 ); | 
| henriquer | 1:e55610b3999a | 126 | |
| henriquer | 3:f723a8456215 | 127 | //tft.printf("tp.x=%d tp.y=%d ", tp.x, tp.y); | 
| henriquer | 1:e55610b3999a | 128 | |
| henriquer | 3:f723a8456215 | 129 | |
| davidprentice | 0:063c3eaefd81 | 130 | } | 
| davidprentice | 0:063c3eaefd81 | 131 | |
| henriquer | 3:f723a8456215 | 132 | } | 
| davidprentice | 0:063c3eaefd81 | 133 | |
| henriquer | 1:e55610b3999a | 134 | |
| henriquer | 1:e55610b3999a | 135 | void bot_1 () | 
| henriquer | 1:e55610b3999a | 136 | { | 
| henriquer | 3:f723a8456215 | 137 | |
| henriquer | 3:f723a8456215 | 138 | |
| henriquer | 3:f723a8456215 | 139 | tft.fillCircle(250,190,20,WHITE); | 
| henriquer | 3:f723a8456215 | 140 | tft.fillCircle(250,130,20,CYAN); | 
| henriquer | 1:e55610b3999a | 141 | |
| henriquer | 1:e55610b3999a | 142 | |
| henriquer | 1:e55610b3999a | 143 | tft.setCursor(40, 50); | 
| henriquer | 3:f723a8456215 | 144 | tft.drawRoundRect(5, 15, 165, 50, 5, WHITE); | 
| henriquer | 3:f723a8456215 | 145 | tft.setTextColor(RED); | 
| henriquer | 1:e55610b3999a | 146 | tft.setTextSize(3); | 
| henriquer | 1:e55610b3999a | 147 | tft.setCursor(15, 30); | 
| henriquer | 1:e55610b3999a | 148 | tft.println("Button 1"); | 
| henriquer | 1:e55610b3999a | 149 | |
| henriquer | 3:f723a8456215 | 150 | tft.drawRoundRect(5, 70, 165, 50, 5, WHITE); | 
| henriquer | 1:e55610b3999a | 151 | tft.setTextColor(BLUE); | 
| henriquer | 1:e55610b3999a | 152 | tft.setTextSize(3); | 
| henriquer | 1:e55610b3999a | 153 | tft.setCursor(15,85); | 
| henriquer | 1:e55610b3999a | 154 | tft.println("Button 2"); | 
| henriquer | 1:e55610b3999a | 155 | |
| henriquer | 1:e55610b3999a | 156 | |
| henriquer | 3:f723a8456215 | 157 | tft.drawRoundRect(5, 125, 165, 50, 5, WHITE); | 
| henriquer | 3:f723a8456215 | 158 | tft.setTextColor(YELLOW); | 
| henriquer | 3:f723a8456215 | 159 | tft.setTextSize(3); | 
| henriquer | 3:f723a8456215 | 160 | tft.setCursor(15,140); | 
| henriquer | 3:f723a8456215 | 161 | tft.println("Button 3"); | 
| henriquer | 3:f723a8456215 | 162 | |
| henriquer | 1:e55610b3999a | 163 | |
| henriquer | 1:e55610b3999a | 164 | } | 
| henriquer | 1:e55610b3999a | 165 | |
| davidprentice | 0:063c3eaefd81 | 166 | void setup(void) | 
| davidprentice | 0:063c3eaefd81 | 167 | { | 
| davidprentice | 0:063c3eaefd81 | 168 | |
| davidprentice | 0:063c3eaefd81 | 169 | tft.reset(); | 
| henriquer | 1:e55610b3999a | 170 | tft.begin(); | 
| davidprentice | 0:063c3eaefd81 | 171 | tft.setRotation(Orientation); | 
| davidprentice | 0:063c3eaefd81 | 172 | tft.fillScreen(BLACK); | 
| henriquer | 1:e55610b3999a | 173 | bot_1(); | 
| davidprentice | 0:063c3eaefd81 | 174 | show_tft(); | 
| davidprentice | 0:063c3eaefd81 | 175 | |
| davidprentice | 0:063c3eaefd81 | 176 | |
| davidprentice | 0:063c3eaefd81 | 177 | delay(1000); | 
| davidprentice | 0:063c3eaefd81 | 178 | } | 
| davidprentice | 0:063c3eaefd81 | 179 | |
| davidprentice | 0:063c3eaefd81 | 180 | void loop() | 
| davidprentice | 0:063c3eaefd81 | 181 | { | 
| davidprentice | 0:063c3eaefd81 | 182 | |
| davidprentice | 0:063c3eaefd81 | 183 | } | 
| davidprentice | 0:063c3eaefd81 | 184 |