Está en la página 1de 3

CONTROL DE KEYPAD A PYTHON

Juan David Solarte Moreno


March 5, 2019

1 Introducción
Este informe describe los pasos para imprimir los caracteres y umeros del
teclado 4x4.

2 Objetivos
• Simular códigos funcionales.

• Recordar los conceptos básicos de programación.


• Lograr que imprima los caracteres del teclado 4x4.
• Generar una interfaz fácil de controlar.

3 Procedimiento
Elementos usados:

• Arduino uno.
• Teclado matricial 4x4.
• Ocho cables dupont jumpers

3.1 Código para arduino


const int numRows = 4;
const int numCols = 4;
const int debounceTime = 50;
const char keymap[numRows][numCols] = {
{ ’1’, ’2’, ’3’,’A’ },
{ ’4’, ’5’, ’6’,’B’ },
{ ’7’, ’8’, ’9’,’C’ },
{ ’*’, ’0’, ’# ’,’D’ }
};
const int rowPins[numRows] = {11,10,9,8};
const int colPins[numCols] = {7,6,5,4};
void setup() {

1
Serial.begin(9600);
for (int row = 0; row ¡ numRows; row++) {
pinMode(rowPins[row],INPUT);
digitalWrite(rowPins[row],HIGH);
}
for (int column = 0; column ¡ numCols; column++) {
pinMode(colPins[column],OUTPUT);
digitalWrite(colPins[column],HIGH);
}
}
void loop() {
char key = getKey();
if( key != 0)
Serial.println(key);
delay(10);
}
}
char getKey(){
char key = 0;
for(int column = 0; column ¡ numCols; column++) {
digitalWrite(colPins[column],LOW);
for(int row = 0; row ¡ numRows; row++){
if(digitalRead(rowPins[row]) == LOW){
delay(debounceTime);
while(digitalRead(rowPins[row]) == LOW) ;
key = keymap[row][column];
}
}
digitalWrite(colPins[column],HIGH);
}
return key;
}

3.2 Código para Python


# import the serial library
import serial, time
# Boolean variable that will represent whether or not the arduino is con-
nected
connected = False
# open the serial port that your arduino is connected to.
ser = serial.Serial(’COM3’, 9600)
print(ser.name)
# loop until the arduino tells us the serial connection is ready
while not connected:
serin = ser.read()
connected = True
# if serial available save value in var, print value and clear it afterwards
for new input while True:
var=ser.read()

2
print(var)
del var
# close the port and end the program
ser.close()

También podría gustarte