Advertisement
RuiViana

Teclado 4x4

Jun 27th, 2018
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. //http://blog.vidadesilicio.com.br/arduino/leitura-de-teclado-matricial-e-multiplexacao/
  2. #include <Keypad.h>
  3.  
  4. const byte row_size = 4;                       // Quantidade de linhas.
  5. const byte col_size = 4;                       // Quantidade de colunas.
  6.  
  7. const char keys[row_size][col_size] = {           // Mapa de teclas do teclado.
  8.   { '1', '2', '3', 'A' },
  9.   { '4', '5', '6', 'B' },
  10.   { '7', '8', '9', 'C' },
  11.   { '*', '0', '#', 'D' }
  12. };
  13. byte row_pin[row_size] = {4, 5, 6, 7};   // Pinos que estão ligados as linhas.
  14. byte col_pin[col_size] = {8, 9, 10, 11}; // Pinos que estão ligados as colunas.
  15.  
  16. Keypad keypad = Keypad(makeKeymap(keys), row_pin, col_pin, row_size, col_size);
  17.  
  18. void setup() {
  19.   Serial.begin(9600);
  20. }
  21.  
  22. void loop() {
  23.   char key = keypad.getKey();   // Retorna a última tecla que foi apertada.
  24.   if (key != NO_KEY) Serial.println(key); // Imprime tecla na porta serial.
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement