Ultizin

kk

Jun 21st, 2023
787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 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.          
  107.     if (tecla_pressionada == '#') {
  108.       Ligar = true;
  109.             lcd.setCursor(0, 1);
  110.             lcd.print(Tempo);
  111.  
  112.            if (Ligar = true && Tempo > 0){
  113.                    Tempo--;
  114.     } else {
  115.       Ligar = false;
  116.     }
  117.     }
  118.  
  119. //numeros
  120.     if (tecla_pressionada == '1') {
  121.         Tempo = 1;
  122.             lcd.setCursor(0, 1);
  123.             lcd.print(Tempo);
  124. }
  125.  
  126.     if (tecla_pressionada == '2') {
  127.         Tempo = 2;
  128.             lcd.setCursor(0, 1);
  129.             lcd.print(Tempo);
  130. }
  131.  
  132.     if (tecla_pressionada == '3') {
  133.         Tempo = 3;
  134.             lcd.setCursor(0, 1);
  135.             lcd.print(Tempo);
  136. }
  137.          
  138.     }
  139.  
  140.     }
Advertisement
Add Comment
Please, Sign In to add comment