Created
September 7, 2017 00:49
-
-
Save fedescarpa/64e6b5cd6dff328fcc578c890adc1b64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int ledError = 51; | |
const int enable = 52; | |
const int buzzer = 53; | |
const int fila1 = 31; | |
const int fila2 = 32; | |
const int fila3 = 33; | |
const int fila4 = 34; | |
const int columna1 = 41; | |
const int columna2 = 42; | |
const int columna3 = 43; | |
int filas[] = {fila1, fila2, fila3, fila4}; | |
int columnas[] = {columna1, columna2, columna3}; | |
const int cantidadFilas = 4; | |
const int cantidadColumnas = 3; | |
char Teclas [][3] = | |
{ | |
{'1','2','3'}, | |
{'4','5','6'}, | |
{'7','8','9'}, | |
{'*','0','#'} | |
}; | |
boolean Prendidas [][3] = | |
{ | |
{false,false,false}, | |
{false,false,false}, | |
{false,false,false}, | |
{false,false,false} | |
}; | |
boolean buzzerState = false; | |
void setup() { | |
//start serial communication | |
pinMode(columna1, OUTPUT); | |
pinMode(columna2, OUTPUT); | |
pinMode(columna3, OUTPUT); | |
pinMode(ledError, OUTPUT); | |
pinMode(buzzer, OUTPUT); | |
pinMode(enable, INPUT); | |
pinMode(fila1, INPUT); | |
pinMode(fila2, INPUT); | |
pinMode(fila3, INPUT); | |
pinMode(fila4, INPUT); | |
digitalWrite(columna1, HIGH); | |
digitalWrite(columna2, LOW); | |
digitalWrite(columna3, LOW); | |
Serial.begin(9600); | |
} | |
void loop() { | |
int prendido = digitalRead(enable); | |
if (prendido == HIGH) { | |
for(int numeroFila = 0; numeroFila < cantidadFilas; numeroFila++) { | |
for(int numeroColumna = 0; numeroColumna < cantidadColumnas; numeroColumna++) { | |
digitalWrite(buzzer, HIGH); | |
digitalWrite(ledError, HIGH); | |
delayMicroseconds(100); | |
digitalWrite(buzzer, LOW); | |
prenderColumna(numeroColumna); | |
if (sePrendio(numeroFila, numeroColumna)) { | |
Serial.println(Teclas[numeroFila][numeroColumna]); | |
} | |
} | |
} | |
} | |
digitalWrite(ledError, LOW); | |
} | |
boolean sePrendio(int numeroFila, int numeroColumna) { | |
int antes = digitalRead(filas[numeroFila]); | |
int estabaPrendida = Prendidas[numeroFila][numeroColumna]; | |
boolean estaPrendida = antes == HIGH; | |
Prendidas[numeroFila][numeroColumna] = estaPrendida; | |
return !estabaPrendida && estaPrendida; | |
} | |
void prenderColumna(int numeroColumna) { | |
digitalWrite(columna1, numeroColumna == 0 ? HIGH : LOW); | |
digitalWrite(columna2, numeroColumna == 1 ? HIGH : LOW); | |
digitalWrite(columna3, numeroColumna == 2 ? HIGH : LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment