Hello
How can I move a Motor DC with a code in the Keypad?
This is my Code,
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//---[Motores DC]---
int MX1 = 24;
int MX2 = 25;
//PWM 0
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
int read_LCD_buttons()
{ adc_key_in = analogRead(0); // Leemos A0
if (adc_key_in > 900) return btnNONE;
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
return btnNONE;
}
char codigo[3];
int espacio = 0;
int cuadro = 0;
int fila = 0;
const byte Filas = 4; //KeyPad de 4 filas
const byte Cols = 4; //y 4 columnas
byte Pins_Filas[] = {53, 51, 49, 47}; //Pines Arduino para las filas.
byte Pins_Cols[] = {45, 43, 41, 39}; // Pines Arduino para las columnas.
char Teclas [ Filas ][ Cols ] =
{
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
Keypad Teclado = Keypad(makeKeymap(Teclas), Pins_Filas, Pins_Cols, Filas, Cols);
int numero = 0;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Codigo libro:");
pinMode(MX1,OUTPUT);
pinMode(MX2,OUTPUT);
}
void loop() {
lcd_key = read_LCD_buttons();
char tecla = Teclado.getKey();
if (tecla != 0)
{
lcd.setCursor(espacio,1);
lcd.print(tecla);
espacio++;
}
codigo[numero]=tecla;
if( lcd_key == btnUP)
{
lcd.setCursor(4,1);
lcd.print("Aceptado");
}
if (espacio == 3)
{
espacio = 0;
}
if( lcd_key == btnSELECT)
{
lcd.setCursor(0,1);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Codigo libro:");
espacio=0;
}
if(codigo[numero]==120){ // Coordenada X=1, Y=1
analogWrite(0,255);
digitalWrite(MX1,LOW);
digitalWrite(MX2,HIGH);
delay(4000);
analogWrite(0,0);
digitalWrite(MX1,LOW);
digitalWrite(MX2,LOW);
}
}
I try to save the information of keypad in a array but nothing happens.
Thanks!