Advertisement
Ultizin

codigo

Jun 21st, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. /* Bibliotecas: */
  2.  
  3. #include <LiquidCrystal.h>
  4. #include <Keypad.h>
  5.  
  6. /* Variaveis: */
  7.  
  8. int Tempo = 0; /* Coluna 1 */
  9. boolean Ligar = false;
  10.  
  11. #define buzzer A1
  12.  
  13. /* Portas Tela LCD: */
  14.  
  15. LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
  16.  
  17.  
  18.  
  19. /* Setup e Loop: */
  20. /* Código: */
  21.  
  22. const byte qtdLinhas = 4;
  23. const byte qtdColunas = 4;
  24.  
  25. char matriz_teclas[qtdLinhas][qtdColunas] = {
  26.  
  27. {'1', '2', '3', 'A'},
  28. {'4', '5', '6', 'B'},
  29. {'7', '8', '9', 'C'},
  30. {'*', '0', '#', 'D'}
  31.  
  32. };
  33.  
  34. /* Portas Trocadas: 5 = 1 | 4 = 0 | 3 = 13 | 2 = (Não tem) */
  35. byte PinosqtdLinhas[qtdLinhas] = {9, 8, 7, 6};
  36. byte PinosqtdColunas[qtdColunas] = {A2, A3, 13, A0};
  37.  
  38. Keypad meuteclado = Keypad( makeKeymap(matriz_teclas),
  39. PinosqtdLinhas, PinosqtdColunas, qtdLinhas, qtdColunas);
  40.  
  41. void setup() {
  42.  
  43. Serial.begin(9600);
  44.  
  45. /* Tela LCD */
  46.  
  47. lcd.begin(2, 16);
  48. lcd.clear();
  49. lcd.setCursor(0, 0);
  50. lcd.print("Defina o Tempo:");
  51. lcd.setCursor(0, 1);
  52. lcd.print(Tempo);
  53.  
  54.  
  55. /* Teclado Matricial de Membrana */
  56.  
  57. Serial.println("Aperte uma tecla...");
  58. Serial.println();
  59.  
  60. /* Buzzer */
  61.  
  62. pinMode(buzzer, OUTPUT);
  63.  
  64. }
  65.  
  66.  
  67.  
  68. void loop() {
  69.  
  70. /* Tela LCD */
  71.  
  72. if (Serial.available()) {
  73.  
  74. char cr = Serial.read();
  75. if (cr == '%') {
  76. lcd.clear();
  77.  
  78. }
  79. else if (cr == '>') {
  80.  
  81. lcd.setCursor(0, 1);
  82.  
  83. }
  84.  
  85. else {
  86. lcd.write(cr);
  87.  
  88. }
  89.  
  90. }
  91.  
  92. /* Teclado Matricial de Membrana */
  93.  
  94. char tecla_pressionada = meuteclado.getKey();
  95.  
  96. if (tecla_pressionada) {
  97.  
  98. tone(buzzer, 800,100);
  99. lcd.clear();
  100. lcd.setCursor(0, 0);
  101. lcd.print("Defina o Tempo:");
  102. Serial.print("Tecla pressionada : ");
  103. Serial.println(tecla_pressionada);
  104.  
  105. //funções
  106. if (tecla_pressionada == '#') {
  107. Ligar = true;
  108. }
  109.  
  110. if (Ligar = true && Tempo > 0){
  111. Tempo--;
  112. lcd.setCursor(0, 1);
  113. lcd.print(Tempo);
  114.  
  115. } else {
  116. Ligar = false;
  117. }
  118.  
  119. if (tecla_pressionada == 'D') {
  120. Tempo = 0;
  121.  
  122. }
  123.  
  124. if (Ligar = false){
  125. lcd.setCursor(0, 1);
  126. lcd.print(Tempo);
  127. }
  128.  
  129. //numeros
  130.  
  131. if (tecla_pressionada == '1') {
  132. Tempo = 1;
  133. lcd.setCursor(0, 1);
  134. lcd.print(Tempo);
  135. }
  136.  
  137. if (tecla_pressionada == '2') {
  138. Tempo = 2;
  139. lcd.setCursor(0, 1);
  140. lcd.print(Tempo);
  141. }
  142.  
  143. if (tecla_pressionada == '3') {
  144. Tempo = 3;
  145. lcd.setCursor(0, 1);
  146. lcd.print(Tempo);
  147. }
  148.  
  149. if (tecla_pressionada == '4') {
  150. Tempo = 4;
  151. lcd.setCursor(0, 1);
  152. lcd.print(Tempo);
  153. }
  154.  
  155. if (tecla_pressionada == '5') {
  156. Tempo = 5;
  157. lcd.setCursor(0, 1);
  158. lcd.print(Tempo);
  159. }
  160.  
  161. if (tecla_pressionada == '6') {
  162. Tempo = 6;
  163. lcd.setCursor(0, 1);
  164. lcd.print(Tempo);
  165. }
  166.  
  167. if (tecla_pressionada == '7') {
  168. Tempo = 7;
  169. lcd.setCursor(0, 1);
  170. lcd.print(Tempo);
  171. }
  172.  
  173. if (tecla_pressionada == '8') {
  174. Tempo = 8;
  175. lcd.setCursor(0, 1);
  176. lcd.print(Tempo);
  177. }
  178.  
  179. if (tecla_pressionada == '9') {
  180. Tempo = 9;
  181. lcd.setCursor(0, 1);
  182. lcd.print(Tempo);
  183. }
  184.  
  185. if (tecla_pressionada == '0') {
  186. Tempo = 0;
  187. lcd.setCursor(0, 1);
  188. lcd.print(Tempo);
  189. }
  190. }
  191.  
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement