#include <Keypad.h>
#define filas 2
#define columnas 5
char position; //(posicion baja) 0 Carga; 1 Lavado; 2 Enjuague; 3 Secado; 4 Salida
char position0; //(posicion alta) 5 Carga; 6 Lavado; 7 Enjuague; 8 Secado; 9 Salida
char target; //posicion a la que se tiene que mover el carro
byte dir;
byte pinesFilas[] = {9,8};
byte pinesColumnas[] = {7,6,5,4,3};
char teclas[2][5] = {{'5','6','7','8','9'},
{'0','1','2','3','4'}};
Keypad teclado1 = Keypad( makeKeymap(teclas), pinesFilas, pinesColumnas, filas, columnas);
void setup() {
Serial.begin(9600);
Serial.println("Teclado 4x4 con Biblioteca Keypad");
Serial.println();
pinMode(22, OUTPUT);
pinMode(23, OUTPUT);
}
void loop() {
trackposition ();
target='2';
move();
}
void trackposition ()
{
position = teclado1.getKey();
if (position)
{
if (position != position0)
{
position0 = position;
Serial.println(position);
}
}
}
void move() {
if(target==position0){
dir=0;
}
else if(target>position0){
dir=1;
}
else if(target<position0){
dir=2;
}
switch(dir){
case 0:
digitalWrite(22, LOW);
digitalWrite(23, LOW);
break;
case 1:
digitalWrite(22, HIGH);
break;
case 2:
digitalWrite(23, HIGH);
break;
}
}