HomeProdutos › Teclado membrana com 16 teclas

Teclado membrana com 16 teclas

Os pinos foram identificados por mim na foto apenas. O teclado não tem as marcações.

Você precisa da biblioteca Keypad. Com ela,  o teclado pode ser ligado diretamente a oito pinos do Arduino, sem necessidade de qualquer outro componente. Atenção: a versão mais recente da biblioteca funciona com Arduino 0.2x ou 1.x, mas para que os exemplos apareçam na lista do Arduino 0.2x você precisa ir em cada diretório dentro de Examples e renomear os arquivos .ino para .pde.

Conecte o teclado aos pinos 2 a 9 do Arduino. Abra o exemplo keypad -> CustomKeypad e faça a seguinte modificação:


char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8, 9}; //connect to the column pinouts of the keypad

Abra o Serial Monitor. Cada tecla pressionada deve aparecer corretamente na porta serial.

Esta versão da biblioteca também permite detectar mais de uma tecla pressionada. Use este sketch para testar essa capacidade:

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {6, 7, 8,9}; //connect to the column pinouts of the kpd

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
Serial.begin(9600);
}

void loop(){

if (kpd.getKeys())
{

for (int i=0; i<LIST_MAX; i++)   // Scan the entire list for any active keys.
{
if (kpd.key[i].kchar)    // Check for an active key.
{
switch (kpd.key[i].kstate) {
case HOLD:
Serial.print("Key ");
Serial.print(kpd.key[i].kchar);
Serial.print(" is being HELD and the state ");
if (!kpd.key[i].stateChanged)
Serial.println("has not changed.");
else
Serial.println("has changed.");
break;
case PRESSED:
Serial.print("Key ");
Serial.print(kpd.key[i].kchar);
Serial.print(" is PRESSED and the state ");
if (!kpd.key[i].stateChanged)
Serial.println("has not changed.");
else
Serial.println("has changed.");
break;
case RELEASED:
Serial.print("Key ");
Serial.print(kpd.key[i].kchar);
Serial.print(" has been RELEASED and the state ");
if (!kpd.key[i].stateChanged)
Serial.println("has not changed.");
else
Serial.println("has changed.");
break;
default:
Serial.print("Key ");
Serial.print(kpd.key[i].kchar);
Serial.print(" is IDLE and the state ");
if (!kpd.key[i].stateChanged)
Serial.println("has not changed.");
else
Serial.println("has changed.");
}
}
}
}
}

1 Comments.[ Leave a comment ]

  1. […] é o mesmo teclado membrana que eu já oferecia, agora com o acréscimo de um cabo que faz a interface I2C, reduzindo de oito […]

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">