Advertisement
RuiViana

Digita*

Nov 25th, 2016
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. //Programa : Teclado matricial membrana 3x4 - Biblioteca Keypad
  2. #include <Keypad.h>                         //Carrega a biblioteca Keypad
  3. const byte LINHAS = 4;                      //Definicao da quantidade de linhas e colunas
  4. const byte COLUNAS = 3;
  5. char matriz_teclas[LINHAS][COLUNAS] =       //Matriz de caracteres
  6. {
  7.   {'1', '2', '3'},
  8.   {'4', '5', '6'},
  9.   {'7', '8', '9'},
  10.   {'*', '0', '#'}
  11. };
  12. byte PinosLinhas[LINHAS] = {4, 5, 6, 7};    //Definicao dos pinos das linhas
  13. byte PinosColunas[COLUNAS] = {8, 9, 10};    //Definicao dos pinos das colunas
  14. //Inicializa o teclado
  15. Keypad meuteclado = Keypad( makeKeymap(matriz_teclas), PinosLinhas, PinosColunas, LINHAS, COLUNAS);   //Inicializa o teclado
  16. String numero = "";                                                                                   //Numero de 4 digitos
  17. //--------------------------------------
  18. void setup()
  19. {
  20.   Serial.begin(9600);
  21.   Serial.println("Teclado 3x4 - Exemplo biblioteca Keypad");
  22.   Serial.println("Aguardando acionamento das teclas...");
  23.   Serial.println();
  24. }
  25. //--------------------------------------
  26. void loop()
  27. {
  28.   numero = readval();
  29.   Serial.println(numero);
  30. }
  31. //--------------------------------------
  32. String readval()
  33. {
  34.   String myString = "";
  35.   char keyPressed = meuteclado.getKey();
  36.   while (keyPressed != '#')
  37.   {
  38.     keyPressed = meuteclado.getKey();
  39.     if ((keyPressed != NO_KEY) && (keyPressed != '#'))
  40.     {
  41.       myString.concat(keyPressed);
  42.     }
  43.     if (keyPressed == '*')
  44.     myString = "";
  45.   }
  46.   return (myString.substring(0, 4));
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement