/////PRUEBA/////
#include <Keypad.h>
#include <string.h>
int i;
byte pos_led = 22;
unsigned long vel=300;
unsigned long t_actual, t_pasado;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {39, 41, 43, 45}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {38, 40, 42, 44}; //connect to the column pinouts of the keypad
Keypad teclado = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void conf_pines(void);
void encender_pines(void);
void apagar_pines(void);
void ejecuta_secuencia(void);
void setup() {
// put your setup code here, to run once:
//Serial.begin (9600);
conf_pines ();
encender_pines ();
apagar_pines();
pinMode (13, OUTPUT);
t_actual = t_pasado = 0; // funcion hecha con millis
}
void loop() {
ejecuta_secuencia();
}
void conf_pines(void){
for(i=22;i<=36;i+=2){
pinMode(i,OUTPUT);
}
}
void apagar_pines(void){
for(i=22;i<=36;i+=2){
digitalWrite(i,LOW);
}
}
void encender_pines(void){
for(i=22;i<=36;i+=2){
digitalWrite(i,HIGH);
}
}
void ejecuta_secuencia(void){
char tecla = teclado.getKey();
if (tecla) {
switch(tecla){
case '1':
t_actual = millis(); // referencia de tiempo
if((t_actual-t_pasado)>=vel){
apagar_pines();
digitalWrite(pos_led,HIGH);
pos_led +=2;
if(pos_led > 36){
pos_led = 22;
}
}t_pasado=t_actual;
break;
case '2':
t_actual = millis(); // referencia de tiempo
if((t_actual-t_pasado)>=vel){
apagar_pines();
digitalWrite(pos_led,HIGH);
pos_led -=2;
if(pos_led < 22){
pos_led = 36;
}
}t_pasado=t_actual;
break;
}
}
}
Por favor necesito ayuda con ese código ya que no se activa la secuencia (1 o 2) al presionar en el teclado el caracter ya que recorre cada posicion cada vez que se presiona el la misma tecla ¿QUE DEBO HACER ?
#include <Keypad.h>
#include <string.h>
int i;
byte pos_led = 22;
unsigned long vel=300;
unsigned long t_actual, t_pasado;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {39, 41, 43, 45}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {38, 40, 42, 44}; //connect to the column pinouts of the keypad
Keypad teclado = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void conf_pines(void);
void encender_pines(void);
void apagar_pines(void);
void ejecuta_secuencia(void);
void setup() {
// put your setup code here, to run once:
//Serial.begin (9600);
conf_pines ();
encender_pines ();
apagar_pines();
pinMode (13, OUTPUT);
t_actual = t_pasado = 0; // funcion hecha con millis
}
void loop() {
ejecuta_secuencia();
}
void conf_pines(void){
for(i=22;i<=36;i+=2){
pinMode(i,OUTPUT);
}
}
void apagar_pines(void){
for(i=22;i<=36;i+=2){
digitalWrite(i,LOW);
}
}
void encender_pines(void){
for(i=22;i<=36;i+=2){
digitalWrite(i,HIGH);
}
}
void ejecuta_secuencia(void){
char tecla = teclado.getKey();
if (tecla) {
switch(tecla){
case '1':
t_actual = millis(); // referencia de tiempo
if((t_actual-t_pasado)>=vel){
apagar_pines();
digitalWrite(pos_led,HIGH);
pos_led +=2;
if(pos_led > 36){
pos_led = 22;
}
}t_pasado=t_actual;
break;
case '2':
t_actual = millis(); // referencia de tiempo
if((t_actual-t_pasado)>=vel){
apagar_pines();
digitalWrite(pos_led,HIGH);
pos_led -=2;
if(pos_led < 22){
pos_led = 36;
}
}t_pasado=t_actual;
break;
}
}
}
Por favor necesito ayuda con ese código ya que no se activa la secuencia (1 o 2) al presionar en el teclado el caracter ya que recorre cada posicion cada vez que se presiona el la misma tecla ¿QUE DEBO HACER ?