
TFT_Touch_Menu_Encoder
Dependencies: mbed TouchScreen_kbv_mbed MCUFRIEND_kbv_R299 GLUE_STUFF_kbv EncoderAli ADA_GFX_kbv_R1107
Revision 5:64202050310c, committed 2022-04-18
- Comitter:
- henriquer
- Date:
- Mon Apr 18 18:07:23 2022 +0000
- Parent:
- 4:87a2ee357e78
- Commit message:
- TFT_ Menu_ KY-040
Changed in this revision
diff -r 87a2ee357e78 -r 64202050310c EncoderAli.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EncoderAli.lib Mon Apr 18 18:07:23 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/zelmic/code/EncoderAli/#e1a3b380b0d6
diff -r 87a2ee357e78 -r 64202050310c TFT_MENU.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TFT_MENU.cpp Mon Apr 18 18:07:23 2022 +0000 @@ -0,0 +1,239 @@ + + +//******************************Henrique**************************************// + +//********************Programa Exemplo Menu com botões***********************// + + +//***********************Display TFT-ILI9341 Toutch***************************// + + +//*****************************Biblioteca*************************************// + + +#include "mbed.h" +#include "Arduino.h" +#include <MCUFRIEND_kbv.h> +MCUFRIEND_kbv tft; +#include "TouchScreen_kbv_mbed.h" +#include "Encoder.h" + +//************************Configuração do Display*****************************// + +//****************************************************************************// + +const int TS_LEFT=121,TS_RT=922,TS_TOP=82,TS_BOT=890; +const PinName XP = D8, YP = A3, XM = A2, YM = D9; //next common configuration +DigitalInOut YPout(YP); +DigitalInOut XMout(XM); + + +long map(long x, long in_min, long in_max, long out_min, long out_max) +{ + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +} + +TouchScreen_kbv ts = TouchScreen_kbv(XP, YP, XM, YM, 300); +TSPoint_kbv tp; + +// Valores para detectar a pressão do toque + +#define MINPRESSURE 10 +#define MAXPRESSURE 1000 + +//****************************************************************************// + +//****************************************************************************// + +//***********************Orientação Display***********************************// + +uint8_t Orientation = 0; + +//****************************************************************************// + +//****************************************************************************// + + +bool botao_1 = 0; +bool botao_2 = 0; +bool botao_3 = 0; +int pulse; +bool sw; + +//***********************Tabela de Cores**************************************// + +#define BLACK 0x0000 +#define BLUE 0x001F +#define RED 0xF800 +#define GREEN 0x07E0 +#define CYAN 0x07FF +#define MAGENTA 0xF81F +#define YELLOW 0xFFE0 +#define WHITE 0xFFFF + +//****************************************************************************// + +//****************************************************************************// + + +void draw() + +{ + + tft.drawRoundRect(5, 15, 154, 50, 5, WHITE); + tft.setTextColor(GREEN); + tft.setTextSize(3); + tft.setCursor(15, 30); + tft.println("Button 1"); + + tft.drawRoundRect(5, 70, 154, 50, 5, WHITE); + tft.setTextColor(GREEN); + tft.setTextSize(3); + tft.setCursor(15,85); + tft.println("Button 2"); + + tft.drawRoundRect(5, 125, 154, 50, 5, WHITE); + tft.setTextColor(GREEN); + tft.setTextSize(3); + tft.setCursor(15,140); + tft.println("Button 3"); + +} + + +void show_tft(void) +{ + + EncoderAli Enc(PB_13,PB_14,PB_15); //DT, CLK, SW + Enc.setRange(1,16); + + + tft.setTextSize(2); + + + tft.setTextColor(MAGENTA,BLUE); + + while (1) { + + pulse = Enc.getState(); + sw = Enc.getButtonState(); + printf("\n\r PULSOS: %d; ",Enc.getState()); + tp = ts.getPoint(); + YPout.output(); + XMout.output(); + + if (tp.z < MINPRESSURE && tp.z > MAXPRESSURE) + + tp.x = tft.width() - (map(tp.x, TS_RT, TS_LEFT, tft.width(), 0)); + tp.y = tft.height() - (map(tp.y, TS_BOT, TS_TOP, tft.height(), 0)); + + + + if (pulse>=2 && pulse<=5) { + + if(sw==true) { + + tft.fillRoundRect(5, 15, 154, 50, 5, RED); + tft.setCursor(15, 30); + tft.println("Button 1"); + //tft.fillScreen(BLUE); + // sw =!sw; + } + + else { + + tft.fillRoundRect(5, 15, 154, 50, 5, BLACK); + tft.drawRoundRect(5, 15, 154, 50, 5, WHITE); + tft.setTextColor(GREEN); + tft.setTextSize(3); + tft.setCursor(15, 30); + tft.println("Button 1"); + //tft.fillScreen(BLACK); + + //sw =!sw; + + } + } + + + if (pulse>=6 && pulse<=10) { + + if(sw==true) { + + tft.fillRoundRect(5, 70, 154, 50, 5, BLUE); + tft.setTextColor(GREEN); + tft.setTextSize(3); + tft.setCursor(15, 85); + tft.println("Button 2"); + botao_2 =!botao_2; + } + + else { + + + tft.fillRoundRect(5, 70, 154, 50, 5, BLACK); + tft.drawRoundRect(5, 70, 154, 50, 5, WHITE); + tft.setTextColor(GREEN); + tft.setTextSize(3); + tft.setCursor(15,85); + tft.println("Button 2"); + botao_2 =!botao_2; + } + } + + if (pulse>11 && pulse<=14) { + + if(sw==true) { + + tft.fillRoundRect(5, 125, 154, 50, 5, MAGENTA); + tft.setTextColor(GREEN); + tft.setTextSize(3); + tft.setCursor(15, 140); + tft.println("Button 3"); + botao_3 =!botao_3; + } + + else { + + tft.fillRoundRect(5, 125, 154, 50, 5, BLACK); + tft.drawRoundRect(5, 125, 154, 50, 5, WHITE); + tft.setTextColor(GREEN); + tft.setTextSize(3); + tft.setCursor(15,140); + tft.println("Button 3"); + botao_3 =!botao_3; + } + } + + } +} + + + + + +void setup(void) +{ + + + + tft.reset(); + tft.begin(); + tft.setRotation(Orientation); + tft.fillScreen(BLACK); + draw(); + show_tft(); + + + delay(1000); +} + +void loop() +{ + + +} + +//****************************************************************************// + +//****************************************************************************// \ No newline at end of file
diff -r 87a2ee357e78 -r 64202050310c TFT_exemplo_6.cpp --- a/TFT_exemplo_6.cpp Tue May 25 15:04:47 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -// ************************** Henrique **************************************// - -// Programa Exemplo 7 - Programa teste para uso de três botões - -// -// ************** Display TFT- ILI9341 Toutch********************************\\ - - -//************************ Biblioteca*****************************************// - - -#include "mbed.h" -#include "Arduino.h" -#include <MCUFRIEND_kbv.h> -MCUFRIEND_kbv tft; -#include "TouchScreen_kbv_mbed.h" - -//************************Configuração do Display*****************************// - -const int TS_LEFT=121,TS_RT=922,TS_TOP=82,TS_BOT=890; -const PinName XP = D8, YP = A3, XM = A2, YM = D9; //next common configuration -DigitalInOut YPout(YP); -DigitalInOut XMout(XM); - - -long map(long x, long in_min, long in_max, long out_min, long out_max) -{ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - -TouchScreen_kbv ts = TouchScreen_kbv(XP, YP, XM, YM, 300); -TSPoint_kbv tp; - -// Valores para detectar a pressão do toque -#define MINPRESSURE 10 -#define MAXPRESSURE 1000 -//****************************************************************************// - - -//***********************Orientação Display**********************************// - -uint8_t Orientation = 0; - -//****************************************************************************// -bool botao_1 = 0; -bool botao_2 = 0; -bool botao_3 = 0; -//***********************Tabela de Cores**************************************// - -#define BLACK 0x0000 -#define BLUE 0x001F -#define RED 0xF800 -#define GREEN 0x07E0 -#define CYAN 0x07FF -#define MAGENTA 0xF81F -#define YELLOW 0xFFE0 -#define WHITE 0xFFFF - -//****************************************************************************// - - -void draw() - -{ - - tft.drawRoundRect(5, 15, 154, 50, 5, WHITE); - tft.setTextColor(GREEN); - tft.setTextSize(3); - tft.setCursor(15, 30); - tft.println("Button 1"); - - tft.drawRoundRect(5, 70, 154, 50, 5, WHITE); - tft.setTextColor(GREEN); - tft.setTextSize(3); - tft.setCursor(15,85); - tft.println("Button 2"); - - tft.drawRoundRect(5, 125, 154, 50, 5, WHITE); - tft.setTextColor(GREEN); - tft.setTextSize(3); - tft.setCursor(15,140); - tft.println("Button 3"); - -} - -void show_tft(void) -{ - - tft.setTextSize(2); - - - tft.setTextColor(MAGENTA,BLUE); - - - while (1) { - tp = ts.getPoint(); - YPout.output(); - XMout.output(); - - if (tp.z < MINPRESSURE && tp.z > MAXPRESSURE) - - tp.x = tft.width() - (map(tp.x, TS_RT, TS_LEFT, tft.width(), 0)); - tp.y = tft.height() - (map(tp.y, TS_BOT, TS_TOP, tft.height(), 0)); - - - - if (tp.x>=240&&tp.x<=475 && tp.y>=260&&tp.y<=310) { - if(botao_1 ==0) { - - tft.fillRoundRect(5, 15, 154, 50, 5, RED); - tft.setTextColor(GREEN); - tft.setTextSize(3); - tft.setCursor(15, 30); - tft.println("Button 1"); - botao_1 =!botao_1; - } - - else { - - tft.fillRoundRect(5, 15, 154, 50, 5, BLACK); - tft.drawRoundRect(5, 15, 154, 50, 5, WHITE); - tft.setTextColor(GREEN); - tft.setTextSize(3); - tft.setCursor(15, 30); - tft.println("Button 1"); - botao_1 =!botao_1; - - } - } - - - if (tp.x>=260&&tp.x<=465 && tp.y>=200&&tp.y<=250) { - if(botao_2 ==0) { - - tft.fillRoundRect(5, 70, 154, 50, 5, BLUE); - tft.setTextColor(GREEN); - tft.setTextSize(3); - tft.setCursor(15, 85); - tft.println("Button 2"); - botao_2 =!botao_2; - } - - else { - - - tft.fillRoundRect(5, 70, 154, 50, 5, BLACK); - tft.drawRoundRect(5, 70, 154, 50, 5, WHITE); - tft.setTextColor(GREEN); - tft.setTextSize(3); - tft.setCursor(15,85); - tft.println("Button 2"); - botao_2 =!botao_2; - } - } - - if (tp.x>=460&&tp.x<=650 && tp.y>=150&&tp.y<=195) { - if(botao_3 ==0) { - - tft.fillRoundRect(5, 125, 154, 50, 5, MAGENTA); - tft.setTextColor(GREEN); - tft.setTextSize(3); - tft.setCursor(15, 140); - tft.println("Button 3"); - botao_3 =!botao_3; - } - - else { - tft.fillRoundRect(5, 125, 154, 50, 5, BLACK); - tft.drawRoundRect(5, 125, 154, 50, 5, WHITE); - tft.setTextColor(GREEN); - tft.setTextSize(3); - tft.setCursor(15,140); - tft.println("Button 3"); - botao_3 =!botao_3; - } - } - - // tft.setCursor(0, (tft.height() * 3) / 4); - // tft.printf("tp.x=%d tp.y=%d ", tp.x, tp.y); - - - } -} - - - - - -void setup(void) -{ - - tft.reset(); - tft.begin(); - tft.setRotation(Orientation); - tft.fillScreen(BLACK); - draw(); - show_tft(); - - - delay(1000); -} - -void loop() -{ - -} -