Advertisement
NapsterMP3

2.4 LCD Touch com infravermelho

Jun 17th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.02 KB | None | 0 0
  1. //Programa : Teste Display Touch Arduino - Touchscreen
  2. //Autor : FILIPEFLOP
  3.  
  4. #include <Adafruit_GFX.h> // Core graphics library
  5. #include <Adafruit_TFTLCD.h> // Hardware-specific library
  6. #include <TouchScreen.h>
  7. #include <EEPROM.h>
  8.  
  9. #define YP A3 // Y+ is on Analog1
  10. #define XM A2 // X- is on Analog2
  11. #define YM 9 // Y- is on Digital7
  12. #define XP 8 // X+ is on Digital6
  13.  
  14. #define TS_MINX 150
  15. #define TS_MINY 120
  16. #define TS_MAXX 920
  17. #define TS_MAXY 940
  18.  
  19. TouchScreen ts = TouchScreen(XP, YP, XM, YM, 100);
  20.  
  21. //Definicao de cores
  22. #define BLACK 0x0000
  23. #define BLUE 0x001F
  24. #define RED 0xF800
  25. #define GREEN 0x07E0
  26. #define CYAN 0x07FF
  27. #define MAGENTA 0xF81F
  28. #define YELLOW 0xFFE0
  29. #define WHITE 0xFFFF
  30.  
  31. //PP_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  32. Adafruit_TFTLCD tft(A3, A2, A1, A0, A4);
  33.  
  34.  
  35. //////////CONFIGURAÇÕES INFRAVERMELHO//////////////////
  36. int IRledPin = 13; // LED connected to digital pin 13
  37.  
  38. // Configurações do tempo - millis()
  39. unsigned long comparativo = 0;
  40. unsigned long tempo_ligado = 0;
  41. unsigned long tempo_desligado = 0;
  42. boolean a=1;
  43.  
  44. //variaveis com os numeros impressos no LCD
  45. int ligado =10;
  46. int desligado =10;
  47.  
  48.  
  49. #define MINPRESSURE 10
  50. #define MAXPRESSURE 1000
  51.  
  52. void setup(void)
  53. {
  54. pinMode(IRledPin, OUTPUT);
  55.  
  56. ligado=EEPROM.read(0);
  57. desligado=EEPROM.read(1);
  58. tempo_ligado= ligado * 60L * 1000L;
  59. tempo_desligado= desligado * 60L * 1000L;
  60.  
  61. //identifier == 0x9341;
  62. tft.reset();
  63. delay(500);
  64. //uint16_t identifier = tft.readRegister(0x0);
  65. //Serial.print("Driver encontrado: ");
  66. //Serial.println(identifier, HEX);
  67.  
  68. tft.begin(0x9341);
  69. //tft.initDisplay();
  70.  
  71. tft.setRotation(1);
  72.  
  73.  
  74. ////////////LOGIN//////
  75. login();
  76. tft.fillScreen(BLACK);
  77.  
  78.  
  79. // Inicio - Texto e botoes
  80. //tft.drawRoundRect(5, 15, 312, 50, 5, WHITE);
  81. tft.drawRoundRect(240, 15, 62, 50, 5, WHITE);
  82. tft.setTextColor(YELLOW);
  83. tft.setTextSize(3);
  84. tft.setCursor(20, 30);
  85. tft.println("LIGADO");
  86.  
  87. //INICIO - TEMPO LIGADO
  88. tft.setCursor(25, 75);
  89. tft.setTextColor(WHITE);
  90. tft.println(ligado);
  91. tft.setTextSize(2);
  92. tft.setCursor(75, 80);
  93. tft.println("minutos");
  94.  
  95.  
  96.  
  97. //INICIO - TEMPO desligado
  98. tft.setTextSize(3);
  99. tft.setCursor(25, 185);
  100. tft.println(desligado);
  101. tft.setTextSize(2);
  102. tft.setCursor(75, 190);
  103. tft.println("minutos");
  104.  
  105.  
  106. //tft.drawRoundRect(5, 70, 312, 50, 5, WHITE);
  107. tft.drawRoundRect(240, 70, 62, 50, 5, WHITE);
  108. //tft.setTextColor(GREEN);
  109. //tft.setTextSize(3);
  110. //tft.setCursor(15, 85);
  111. //tft.println("Led Verde");
  112.  
  113. //tft.drawRoundRect(5, 125, 312, 50, 5, WHITE);
  114. tft.drawRoundRect(240, 125, 62, 50, 5, WHITE);
  115. tft.setTextColor(WHITE);
  116. tft.setTextSize(3);
  117. tft.setCursor(20, 140);
  118. tft.println("DESLIGADO");
  119.  
  120. //tft.drawRoundRect(5, 180, 312, 50, 5, WHITE);
  121. tft.drawRoundRect(240, 180, 62, 50, 5, WHITE);
  122. //tft.setTextColor(RED);
  123. //tft.setTextSize(3);
  124. //tft.setCursor(15, 195);
  125. //tft.println("Led Vermelho");
  126.  
  127. //Preenchimento OFF
  128. tft.setTextColor(WHITE);
  129. tft.setCursor(260, 30);
  130. tft.println("+");
  131. tft.setCursor(260, 85);
  132. tft.println("-");
  133. tft.setCursor(260, 140);
  134. tft.println("+");
  135. tft.setCursor(260, 195);
  136. tft.println("-");
  137. }
  138.  
  139. void loop()
  140. {
  141. unsigned long tempo = millis();
  142.  
  143. if (tempo - comparativo > tempo_ligado & a==1){
  144. a=0;
  145. comparativo=tempo;
  146. desligado_ativado();
  147.  
  148. }
  149.  
  150. if (tempo - comparativo > tempo_desligado & a==0){
  151. a=1;
  152. comparativo=tempo;
  153. ligado_ativado();
  154. }
  155.  
  156.  
  157.  
  158.  
  159.  
  160. TSPoint p = ts.getPoint();
  161. pinMode(XM, OUTPUT);
  162. digitalWrite(XM, LOW);
  163. pinMode(YP, OUTPUT);
  164. digitalWrite(YP, HIGH);
  165. pinMode(YM, OUTPUT);
  166. digitalWrite(YM, LOW);
  167. pinMode(XP, OUTPUT);
  168. digitalWrite(XP, HIGH);
  169.  
  170. if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  171. {
  172. p.x = tft.width() - (map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
  173. p.y = tft.height() - (map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
  174. // Serial.print("py: ");
  175. // Serial.print(p.y);
  176. // Serial.print(" px: ");
  177. // Serial.println(p.x);
  178. if (p.y > 176 & p.y < 215)
  179. {
  180.  
  181.  
  182. //Testa botao ligado +
  183. if (p.x > 235 & p.x < 295)
  184. {
  185. tft.fillRoundRect(241, 16, 60, 48, 5, YELLOW);
  186. delay(50);
  187. tft.fillRoundRect(241, 16, 60, 48, 5, BLACK);
  188. tft.setTextColor(WHITE);
  189. tft.setCursor(260, 30);
  190. tft.println("+");
  191. delay (50);
  192. ligado=ligado+1;
  193. if(ligado==41){ligado=1;}
  194. mostra_ligado(25,75);
  195.  
  196.  
  197.  
  198. /*
  199. if (valor_botao1 == 0)
  200. {
  201. tft.fillRoundRect(241, 16, 60, 48, 5, YELLOW);
  202. // mostra_on(269, 30);
  203. delay(100);
  204. valor_botao1 = !valor_botao1;
  205. }
  206. else
  207. {
  208. tft.fillRoundRect(241, 16, 60, 48, 5, BLACK);
  209. // mostra_off(260, 30);
  210. delay (100);
  211. valor_botao1 = !valor_botao1;
  212. }
  213. */
  214. }
  215.  
  216.  
  217.  
  218.  
  219.  
  220. //Testa botao ligado -
  221. if (p.x > 160 & p.x < 215)
  222. {
  223. tft.fillRoundRect(241, 71, 60, 48, 5, YELLOW);
  224. delay(50);
  225. tft.fillRoundRect(241, 71, 60, 48, 5, BLACK);
  226. tft.setTextColor(WHITE);
  227. tft.setCursor(260, 85);
  228. tft.println("-");
  229. delay (50);
  230. ligado=ligado-1;
  231. if(ligado==0){ligado=40;}
  232. mostra_ligado(25,75);
  233.  
  234.  
  235.  
  236. /*
  237. if (valor_botao2 == 0)
  238. {
  239. tft.fillRoundRect(256, 71, 60, 48, 5, GREEN);
  240. mostra_on(269, 85);
  241. valor_botao2 = !valor_botao2;
  242. }
  243. else
  244. {
  245. tft.fillRoundRect(256, 71, 60, 48, 5, BLACK);
  246. mostra_off(260, 85);
  247. valor_botao2 = !valor_botao2;
  248.  
  249. }
  250. */
  251. }
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258. //Testa botao desligado +
  259. if (p.x > 80 & p.x < 140)
  260. {
  261. tft.fillRoundRect(241, 126, 60, 48, 5, YELLOW);
  262. delay(50);
  263. tft.fillRoundRect(241, 126, 60, 48, 5, BLACK);
  264. tft.setTextColor(WHITE);
  265. tft.setCursor(260, 140);
  266. tft.println("+");
  267. delay (50);
  268. desligado=desligado+1;
  269. if(desligado==41){desligado=1;}
  270. mostra_desligado(25,185);
  271.  
  272. /*
  273. if (valor_botao3 == 0)
  274. {
  275. tft.fillRoundRect(256, 126, 60, 48, 5, BLUE);
  276. mostra_on(269, 140);
  277. valor_botao3 = !valor_botao3;
  278. }
  279. else
  280. {
  281. tft.fillRoundRect(256, 126, 60, 48, 5, BLACK);
  282. mostra_off(260, 140);
  283. valor_botao3 = !valor_botao3;
  284. }
  285. */
  286. }
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295. //Testa botao desligado -
  296. if (p.x > 0 & p.x < 60)
  297. {
  298. tft.fillRoundRect(241, 181, 60, 48, 5, YELLOW);
  299. delay(50);
  300. tft.fillRoundRect(241, 181, 60, 48, 5, BLACK);
  301. tft.setTextColor(WHITE);
  302. tft.setCursor(260, 195);
  303. tft.println("-");
  304. delay (50);
  305. desligado=desligado-1;
  306. if(desligado==0){desligado=40;}
  307. mostra_desligado(25,185);
  308.  
  309. /*
  310. if (valor_botao4 == 0)
  311. {
  312. tft.fillRoundRect(256, 181, 60, 48, 5, RED);
  313. mostra_on(269,195);
  314. valor_botao4 = !valor_botao4;
  315. }
  316. else
  317. {
  318. tft.fillRoundRect(256, 181, 60, 48, 5, BLACK);
  319. mostra_off(260,195);
  320. valor_botao4 = !valor_botao4;
  321. }
  322. */
  323. }
  324.  
  325.  
  326.  
  327. }
  328. }
  329. }
  330.  
  331.  
  332.  
  333.  
  334. void mostra_ligado(int x, int y)
  335. {
  336. tft.fillRoundRect(24, 74, 48,30, 1, BLACK);
  337. tft.setTextSize(3);
  338. tft.setTextColor(WHITE);
  339. tft.setCursor(x, y);
  340. tft.println(ligado);
  341. EEPROM.write(0,ligado);
  342. tempo_ligado= ligado * 60L * 1000L;
  343. //delay(100);
  344. }
  345.  
  346.  
  347. void mostra_desligado(int x, int y)
  348. {
  349. tft.fillRoundRect(25, 180, 48,30, 1, BLACK);
  350. tft.setTextSize(3);
  351. tft.setTextColor(WHITE);
  352. tft.setCursor(x, y);
  353. tft.println(desligado);
  354. EEPROM.write(1,desligado);
  355. tempo_desligado= desligado * 60L * 1000L;
  356. // delay(100);
  357. }
  358.  
  359. void ligado_ativado(){
  360.  
  361. tft.setTextColor(YELLOW);
  362. tft.setTextSize(3);
  363. tft.setCursor(20, 30);
  364. tft.println("LIGADO");
  365.  
  366. tft.setTextColor(WHITE);
  367. tft.setTextSize(3);
  368. tft.setCursor(20, 140);
  369. tft.println("DESLIGADO");
  370.  
  371. infra_liga();
  372. delay(500);
  373. }
  374.  
  375. void desligado_ativado(){
  376.  
  377. tft.setTextColor(WHITE);
  378. tft.setTextSize(3);
  379. tft.setCursor(20, 30);
  380. tft.println("LIGADO");
  381.  
  382. tft.setTextColor(YELLOW);
  383. tft.setTextSize(3);
  384. tft.setCursor(20, 140);
  385. tft.println("DESLIGADO");
  386.  
  387. infra_liga();
  388. delay(500);
  389. }
  390.  
  391. void login()
  392. {
  393. tft.fillScreen(BLACK);
  394. tft.setTextColor(RED);
  395. tft.setTextSize(4);
  396. tft.setCursor(100, 40);
  397. tft.println("Timer");
  398. tft.setTextColor(GREEN);
  399. tft.setCursor(20,90);
  400. tft.println("Climatizador");
  401. tft.setTextColor(BLUE);
  402. tft.setCursor(100,150);
  403. tft.println("Everton");
  404. delay(3000);
  405. }
  406.  
  407.  
  408.  
  409.  
  410. void pulseIR(long microsecs) {
  411. // we'll count down from the number of microseconds we are told to wait
  412.  
  413. cli(); // this turns off any background interrupts
  414.  
  415. while (microsecs > 0) {
  416. // 38 kHz is about 13 microseconds high and 13 microseconds low
  417. digitalWrite(IRledPin, HIGH); // this takes about 3 microseconds to happen
  418. delayMicroseconds(10); // hang out for 10 microseconds
  419. digitalWrite(IRledPin, LOW); // this also takes about 3 microseconds
  420. delayMicroseconds(10); // hang out for 10 microseconds
  421.  
  422. // so 26 microseconds altogether
  423. microsecs -= 26;
  424. }
  425.  
  426. sei(); // this turns them back on
  427. }
  428.  
  429. void infra_liga() {
  430. //Cole no lugar desta descrição o codigo que você coletou
  431. delayMicroseconds(31200);
  432. pulseIR(8720);
  433. delayMicroseconds(4400);
  434. pulseIR(540);
  435. delayMicroseconds(540);
  436. pulseIR(520);
  437. delayMicroseconds(580);
  438. pulseIR(520);
  439. delayMicroseconds(560);
  440. pulseIR(540);
  441. delayMicroseconds(540);
  442. pulseIR(540);
  443. delayMicroseconds(560);
  444. pulseIR(540);
  445. delayMicroseconds(540);
  446. pulseIR(520);
  447. delayMicroseconds(580);
  448. pulseIR(520);
  449. delayMicroseconds(580);
  450. pulseIR(500);
  451. delayMicroseconds(580);
  452. pulseIR(520);
  453. delayMicroseconds(560);
  454. pulseIR(520);
  455. delayMicroseconds(1660);
  456. pulseIR(560);
  457. delayMicroseconds(1640);
  458. pulseIR(500);
  459. delayMicroseconds(1680);
  460. pulseIR(500);
  461. delayMicroseconds(1660);
  462. pulseIR(540);
  463. delayMicroseconds(1660);
  464. pulseIR(500);
  465. delayMicroseconds(1680);
  466. pulseIR(520);
  467. delayMicroseconds(1660);
  468. pulseIR(540);
  469. delayMicroseconds(540);
  470. pulseIR(540);
  471. delayMicroseconds(1640);
  472. pulseIR(560);
  473. delayMicroseconds(540);
  474. pulseIR(520);
  475. delayMicroseconds(580);
  476. pulseIR(520);
  477. delayMicroseconds(560);
  478. pulseIR(540);
  479. delayMicroseconds(540);
  480. pulseIR(520);
  481. delayMicroseconds(1660);
  482. pulseIR(560);
  483. delayMicroseconds(540);
  484. pulseIR(520);
  485. delayMicroseconds(1660);
  486. pulseIR(540);
  487. delayMicroseconds(560);
  488. pulseIR(500);
  489. delayMicroseconds(1660);
  490. pulseIR(540);
  491. delayMicroseconds(1680);
  492. pulseIR(500);
  493. delayMicroseconds(1660);
  494. pulseIR(500);
  495. delayMicroseconds(1680);
  496. pulseIR(500);
  497. delayMicroseconds(600);
  498. pulseIR(500);
  499. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement