Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Programa : Teste Display Touch Arduino - Touchscreen
- //Autor : FILIPEFLOP
- #include <Adafruit_GFX.h> // Core graphics library
- #include <Adafruit_TFTLCD.h> // Hardware-specific library
- #include <TouchScreen.h>
- #include <EEPROM.h>
- #define YP A3 // Y+ is on Analog1
- #define XM A2 // X- is on Analog2
- #define YM 9 // Y- is on Digital7
- #define XP 8 // X+ is on Digital6
- #define TS_MINX 150
- #define TS_MINY 120
- #define TS_MAXX 920
- #define TS_MAXY 940
- TouchScreen ts = TouchScreen(XP, YP, XM, YM, 100);
- //Definicao 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
- //PP_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
- Adafruit_TFTLCD tft(A3, A2, A1, A0, A4);
- //////////CONFIGURAÇÕES INFRAVERMELHO//////////////////
- int IRledPin = 13; // LED connected to digital pin 13
- // Configurações do tempo - millis()
- unsigned long comparativo = 0;
- unsigned long tempo_ligado = 0;
- unsigned long tempo_desligado = 0;
- boolean a=1;
- //variaveis com os numeros impressos no LCD
- int ligado =10;
- int desligado =10;
- #define MINPRESSURE 10
- #define MAXPRESSURE 1000
- void setup(void)
- {
- pinMode(IRledPin, OUTPUT);
- ligado=EEPROM.read(0);
- desligado=EEPROM.read(1);
- tempo_ligado= ligado * 60L * 1000L;
- tempo_desligado= desligado * 60L * 1000L;
- //identifier == 0x9341;
- tft.reset();
- delay(500);
- //uint16_t identifier = tft.readRegister(0x0);
- //Serial.print("Driver encontrado: ");
- //Serial.println(identifier, HEX);
- tft.begin(0x9341);
- //tft.initDisplay();
- tft.setRotation(1);
- ////////////LOGIN//////
- login();
- tft.fillScreen(BLACK);
- // Inicio - Texto e botoes
- //tft.drawRoundRect(5, 15, 312, 50, 5, WHITE);
- tft.drawRoundRect(240, 15, 62, 50, 5, WHITE);
- tft.setTextColor(YELLOW);
- tft.setTextSize(3);
- tft.setCursor(20, 30);
- tft.println("LIGADO");
- //INICIO - TEMPO LIGADO
- tft.setCursor(25, 75);
- tft.setTextColor(WHITE);
- tft.println(ligado);
- tft.setTextSize(2);
- tft.setCursor(75, 80);
- tft.println("minutos");
- //INICIO - TEMPO desligado
- tft.setTextSize(3);
- tft.setCursor(25, 185);
- tft.println(desligado);
- tft.setTextSize(2);
- tft.setCursor(75, 190);
- tft.println("minutos");
- //tft.drawRoundRect(5, 70, 312, 50, 5, WHITE);
- tft.drawRoundRect(240, 70, 62, 50, 5, WHITE);
- //tft.setTextColor(GREEN);
- //tft.setTextSize(3);
- //tft.setCursor(15, 85);
- //tft.println("Led Verde");
- //tft.drawRoundRect(5, 125, 312, 50, 5, WHITE);
- tft.drawRoundRect(240, 125, 62, 50, 5, WHITE);
- tft.setTextColor(WHITE);
- tft.setTextSize(3);
- tft.setCursor(20, 140);
- tft.println("DESLIGADO");
- //tft.drawRoundRect(5, 180, 312, 50, 5, WHITE);
- tft.drawRoundRect(240, 180, 62, 50, 5, WHITE);
- //tft.setTextColor(RED);
- //tft.setTextSize(3);
- //tft.setCursor(15, 195);
- //tft.println("Led Vermelho");
- //Preenchimento OFF
- tft.setTextColor(WHITE);
- tft.setCursor(260, 30);
- tft.println("+");
- tft.setCursor(260, 85);
- tft.println("-");
- tft.setCursor(260, 140);
- tft.println("+");
- tft.setCursor(260, 195);
- tft.println("-");
- }
- void loop()
- {
- unsigned long tempo = millis();
- if (tempo - comparativo > tempo_ligado & a==1){
- a=0;
- comparativo=tempo;
- desligado_ativado();
- }
- if (tempo - comparativo > tempo_desligado & a==0){
- a=1;
- comparativo=tempo;
- ligado_ativado();
- }
- TSPoint p = ts.getPoint();
- pinMode(XM, OUTPUT);
- digitalWrite(XM, LOW);
- pinMode(YP, OUTPUT);
- digitalWrite(YP, HIGH);
- pinMode(YM, OUTPUT);
- digitalWrite(YM, LOW);
- pinMode(XP, OUTPUT);
- digitalWrite(XP, HIGH);
- if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
- {
- p.x = tft.width() - (map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
- p.y = tft.height() - (map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
- // Serial.print("py: ");
- // Serial.print(p.y);
- // Serial.print(" px: ");
- // Serial.println(p.x);
- if (p.y > 176 & p.y < 215)
- {
- //Testa botao ligado +
- if (p.x > 235 & p.x < 295)
- {
- tft.fillRoundRect(241, 16, 60, 48, 5, YELLOW);
- delay(50);
- tft.fillRoundRect(241, 16, 60, 48, 5, BLACK);
- tft.setTextColor(WHITE);
- tft.setCursor(260, 30);
- tft.println("+");
- delay (50);
- ligado=ligado+1;
- if(ligado==41){ligado=1;}
- mostra_ligado(25,75);
- /*
- if (valor_botao1 == 0)
- {
- tft.fillRoundRect(241, 16, 60, 48, 5, YELLOW);
- // mostra_on(269, 30);
- delay(100);
- valor_botao1 = !valor_botao1;
- }
- else
- {
- tft.fillRoundRect(241, 16, 60, 48, 5, BLACK);
- // mostra_off(260, 30);
- delay (100);
- valor_botao1 = !valor_botao1;
- }
- */
- }
- //Testa botao ligado -
- if (p.x > 160 & p.x < 215)
- {
- tft.fillRoundRect(241, 71, 60, 48, 5, YELLOW);
- delay(50);
- tft.fillRoundRect(241, 71, 60, 48, 5, BLACK);
- tft.setTextColor(WHITE);
- tft.setCursor(260, 85);
- tft.println("-");
- delay (50);
- ligado=ligado-1;
- if(ligado==0){ligado=40;}
- mostra_ligado(25,75);
- /*
- if (valor_botao2 == 0)
- {
- tft.fillRoundRect(256, 71, 60, 48, 5, GREEN);
- mostra_on(269, 85);
- valor_botao2 = !valor_botao2;
- }
- else
- {
- tft.fillRoundRect(256, 71, 60, 48, 5, BLACK);
- mostra_off(260, 85);
- valor_botao2 = !valor_botao2;
- }
- */
- }
- //Testa botao desligado +
- if (p.x > 80 & p.x < 140)
- {
- tft.fillRoundRect(241, 126, 60, 48, 5, YELLOW);
- delay(50);
- tft.fillRoundRect(241, 126, 60, 48, 5, BLACK);
- tft.setTextColor(WHITE);
- tft.setCursor(260, 140);
- tft.println("+");
- delay (50);
- desligado=desligado+1;
- if(desligado==41){desligado=1;}
- mostra_desligado(25,185);
- /*
- if (valor_botao3 == 0)
- {
- tft.fillRoundRect(256, 126, 60, 48, 5, BLUE);
- mostra_on(269, 140);
- valor_botao3 = !valor_botao3;
- }
- else
- {
- tft.fillRoundRect(256, 126, 60, 48, 5, BLACK);
- mostra_off(260, 140);
- valor_botao3 = !valor_botao3;
- }
- */
- }
- //Testa botao desligado -
- if (p.x > 0 & p.x < 60)
- {
- tft.fillRoundRect(241, 181, 60, 48, 5, YELLOW);
- delay(50);
- tft.fillRoundRect(241, 181, 60, 48, 5, BLACK);
- tft.setTextColor(WHITE);
- tft.setCursor(260, 195);
- tft.println("-");
- delay (50);
- desligado=desligado-1;
- if(desligado==0){desligado=40;}
- mostra_desligado(25,185);
- /*
- if (valor_botao4 == 0)
- {
- tft.fillRoundRect(256, 181, 60, 48, 5, RED);
- mostra_on(269,195);
- valor_botao4 = !valor_botao4;
- }
- else
- {
- tft.fillRoundRect(256, 181, 60, 48, 5, BLACK);
- mostra_off(260,195);
- valor_botao4 = !valor_botao4;
- }
- */
- }
- }
- }
- }
- void mostra_ligado(int x, int y)
- {
- tft.fillRoundRect(24, 74, 48,30, 1, BLACK);
- tft.setTextSize(3);
- tft.setTextColor(WHITE);
- tft.setCursor(x, y);
- tft.println(ligado);
- EEPROM.write(0,ligado);
- tempo_ligado= ligado * 60L * 1000L;
- //delay(100);
- }
- void mostra_desligado(int x, int y)
- {
- tft.fillRoundRect(25, 180, 48,30, 1, BLACK);
- tft.setTextSize(3);
- tft.setTextColor(WHITE);
- tft.setCursor(x, y);
- tft.println(desligado);
- EEPROM.write(1,desligado);
- tempo_desligado= desligado * 60L * 1000L;
- // delay(100);
- }
- void ligado_ativado(){
- tft.setTextColor(YELLOW);
- tft.setTextSize(3);
- tft.setCursor(20, 30);
- tft.println("LIGADO");
- tft.setTextColor(WHITE);
- tft.setTextSize(3);
- tft.setCursor(20, 140);
- tft.println("DESLIGADO");
- infra_liga();
- delay(500);
- }
- void desligado_ativado(){
- tft.setTextColor(WHITE);
- tft.setTextSize(3);
- tft.setCursor(20, 30);
- tft.println("LIGADO");
- tft.setTextColor(YELLOW);
- tft.setTextSize(3);
- tft.setCursor(20, 140);
- tft.println("DESLIGADO");
- infra_liga();
- delay(500);
- }
- void login()
- {
- tft.fillScreen(BLACK);
- tft.setTextColor(RED);
- tft.setTextSize(4);
- tft.setCursor(100, 40);
- tft.println("Timer");
- tft.setTextColor(GREEN);
- tft.setCursor(20,90);
- tft.println("Climatizador");
- tft.setTextColor(BLUE);
- tft.setCursor(100,150);
- tft.println("Everton");
- delay(3000);
- }
- void pulseIR(long microsecs) {
- // we'll count down from the number of microseconds we are told to wait
- cli(); // this turns off any background interrupts
- while (microsecs > 0) {
- // 38 kHz is about 13 microseconds high and 13 microseconds low
- digitalWrite(IRledPin, HIGH); // this takes about 3 microseconds to happen
- delayMicroseconds(10); // hang out for 10 microseconds
- digitalWrite(IRledPin, LOW); // this also takes about 3 microseconds
- delayMicroseconds(10); // hang out for 10 microseconds
- // so 26 microseconds altogether
- microsecs -= 26;
- }
- sei(); // this turns them back on
- }
- void infra_liga() {
- //Cole no lugar desta descrição o codigo que você coletou
- delayMicroseconds(31200);
- pulseIR(8720);
- delayMicroseconds(4400);
- pulseIR(540);
- delayMicroseconds(540);
- pulseIR(520);
- delayMicroseconds(580);
- pulseIR(520);
- delayMicroseconds(560);
- pulseIR(540);
- delayMicroseconds(540);
- pulseIR(540);
- delayMicroseconds(560);
- pulseIR(540);
- delayMicroseconds(540);
- pulseIR(520);
- delayMicroseconds(580);
- pulseIR(520);
- delayMicroseconds(580);
- pulseIR(500);
- delayMicroseconds(580);
- pulseIR(520);
- delayMicroseconds(560);
- pulseIR(520);
- delayMicroseconds(1660);
- pulseIR(560);
- delayMicroseconds(1640);
- pulseIR(500);
- delayMicroseconds(1680);
- pulseIR(500);
- delayMicroseconds(1660);
- pulseIR(540);
- delayMicroseconds(1660);
- pulseIR(500);
- delayMicroseconds(1680);
- pulseIR(520);
- delayMicroseconds(1660);
- pulseIR(540);
- delayMicroseconds(540);
- pulseIR(540);
- delayMicroseconds(1640);
- pulseIR(560);
- delayMicroseconds(540);
- pulseIR(520);
- delayMicroseconds(580);
- pulseIR(520);
- delayMicroseconds(560);
- pulseIR(540);
- delayMicroseconds(540);
- pulseIR(520);
- delayMicroseconds(1660);
- pulseIR(560);
- delayMicroseconds(540);
- pulseIR(520);
- delayMicroseconds(1660);
- pulseIR(540);
- delayMicroseconds(560);
- pulseIR(500);
- delayMicroseconds(1660);
- pulseIR(540);
- delayMicroseconds(1680);
- pulseIR(500);
- delayMicroseconds(1660);
- pulseIR(500);
- delayMicroseconds(1680);
- pulseIR(500);
- delayMicroseconds(600);
- pulseIR(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement