#include <Keypad.
h>
#include <LiquidCrystal.h>
const byte FILAS = 4;
const byte COLUMNAS = 4;
char CARACTERES[FILAS][COLUMNAS] = {{ '1', '2', '3', '/' },
{ '4', '5', '6', '*' },
{ '7', '8', '9', '-' },
{ 'O', '0', '=', '+' }};
byte PINESFILAS[FILAS] = {34, 36, 38, 40};
byte PINESCOLUMNAS[COLUMNAS] = {42, 44, 46, 48};
Keypad teclado = Keypad(makeKeymap(CARACTERES), PINESFILAS, PINESCOLUMNAS, FILAS,
COLUMNAS);
LiquidCrystal lcd(24, 22, 26, 28, 30, 32);
// Variable de la interrupciones
const int inter0 = 20;
const int inter1 = 21;
const int IN1 = 11;
const int IN2 = 12;
const int ENA = 13;
const int AN0 = A0;
const int AN1 = A1;
float POT0, POT1, POT2, POT3 = 0;
float VM = 0;
char buffer[4];
int numero = 0;
int cont = 0;
int cont3 = 0;
volatile int cont0 = 0;
volatile int cont1 = 0;
volatile int cont2 = 0;
volatile char k;
volatile char vec0[4];
void setup() {
[Link](16,2);
[Link](9600);
pinMode(inter0, INPUT);
pinMode(inter1, INPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENA, OUTPUT);
attachInterrupt(digitalPinToInterrupt(inter0),Interrupcion0,RISING);
attachInterrupt(digitalPinToInterrupt(inter1),Interrupcion1,RISING);
[Link](0,0);
[Link]("CII");
void loop() {
if(cont0 >= 1)
{
k = [Link](); //Captura el caracter del teclado
if (k)
{
if (k >= '0' && k <= '9' && cont <3) //Condiciones para que el teclado solo
tome los números y las cifras que necesitamos
{
buffer[cont++] = k;
[Link](0,0);
[Link]();
[Link]("Tecla Presionada: ");
[Link](0,1);
[Link](k);
}
else if (k == '=')
{
buffer[cont] = '\0'; //Agregamos el caracter nulo
numero = atoi(buffer);
[Link]();
[Link](0,0);
[Link]("Numero Guardado: ");
[Link](0,1);
[Link](numero);
}
else if (k == 'O')
{
numero = 0;
cont = 0;
buffer[4] = 0;
[Link]();
[Link]("Numero borrado");
}
else if (k == '/')
{
if(numero < 555)
{
while ([Link]() == '\0')
{
POT0 = analogRead(AN0);
POT1 = POT0 * (4.76 / 1023);
[Link]();
[Link](0,1);
[Link]("POT0 = ");
[Link](7,1);
[Link](POT1);
VM = map(POT1,0,5,0,numero);
[Link](0,0);
[Link]("Inte0: ");
[Link](8,0);
[Link](cont0);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
analogWrite(ENA,VM);
[Link]();
if(cont1 > 1)
{
break;
}
}
}
else
{
[Link]();
[Link](0,0);
[Link]("El # es > 555");
[Link](0,1);
[Link](numero);
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
}
}
}
else
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
}
///////////////// Inicia Interrupcion 1 ////////////////////////////////////////
if(cont1 >= 1)
{
k = [Link](); //Captura el caracter del teclado
if (k)
{
if (k >= '0' && k <= '9' && cont <3) //Condiciones para que el teclado solo
tome los números y las cifras que necesitamos
{
buffer[cont++] = k;
[Link](0,0);
[Link]();
[Link]("Tecla Presionada: ");
[Link](0,1);
[Link](k);
}
else if (k == '=')
{
buffer[cont] = '\0'; //Agregamos el caracter nulo
numero = atoi(buffer);
[Link]();
[Link](0,0);
[Link]("Numero Guardado: ");
[Link](0,1);
[Link](numero);
}
else if (k == 'O')
{
numero = 0;
cont = 0;
buffer[4] = 0;
[Link]();
[Link]("Numero borrado");
}
else if (k == '/')
{
if(numero > 777)
{
while ([Link]() == '\0')
{
POT2 = analogRead(AN1);
POT3 = POT2 * (4.76 / 1023);
[Link]();
[Link](0,1);
[Link]("POT1 = ");
[Link](7,1);
[Link](POT3);
VM = map(POT3,0,5,0,numero);
[Link](0,0);
[Link]("Inte1: ");
[Link](8,0);
[Link](cont0);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
analogWrite(ENA,VM);
[Link]();
if(cont0 > 1)
{
break;
}
}
}
else
{
[Link]();
[Link](0,0);
[Link]("El # es < 777");
[Link](0,1);
[Link](numero);
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
}
}
}
else
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
}
}
else
{
digitalWrite(ENA, LOW);
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
}
}
void Interrupcion0()
{
cont0++;
cont1 = 0;
delay(30);
}
void Interrupcion1()
{
cont1++;
cont0 = 0;
delay(30);
}