#include <AccelStepper.h>
#include <MultiStepper.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#define ledW 13
const byte filas = 4;
const byte columnas = 4;
byte pinsFilas[filas] = {12, 11, 10, 9};
byte pinsColumnas[columnas] = {7, 4, A2, A3};
LiquidCrystal_I2C lcd(0x27, 16, 2);
//------------------------------------------------------
//Pines Motor Y.
#define dirPinY 6
#define stepPinY 3
#define enablePinY 8
//------------------------------------------------------
//Pines Motor X.
#define dirPinX 5
#define stepPinX 2
#define enablePinX 8
//------------------------------------------------------
AccelStepper stepperY(1, stepPinY, dirPinY);
AccelStepper stepperX(1, stepPinX, dirPinX);
//------------------------------------------------------
//Teclado
int tecla = 0;
int menu_nivel = 0;
int valor = 0;
//------------------------------------------------------
//Valores para configurar en el LCD
int inicio = 0;
int medio = 0;
int final = 0;
//------------------------------------------------------
//configuracion KEYPAD
char opcion_selecionada = ' ';
char keys[filas] [columnas] =
{
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
Keypad teclado = Keypad(makeKeymap(keys), pinsFilas, pinsColumnas, filas, columnas);
//------------------------------------------------------
void setup()
{
pinMode(ledW, OUTPUT);
digitalWrite(ledW, 1);
lcd.init();
lcd.backlight();
//------------------------------------------------------
pinMode(enablePinY, OUTPUT);
digitalWrite(enablePinY, HIGH);
stepperY.setMaxSpeed(1000);
stepperY.setAcceleration(1000);
//------------------------------------------------------
pinMode(enablePinX, OUTPUT);
digitalWrite(enablePinX, HIGH);
stepperX.setMaxSpeed(2000);
stepperX.setAcceleration(2000);
//------------------------------------------------------
}
void loop()
{
lcd.clear();
if (menu_nivel == 0){
lcd.setCursor(0,0);
lcd.print(" Menu config! ");
lcd.setCursor(0,1);
lcd.print(" ");
delay(500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("A:Inicio B:Medio");
lcd.setCursor(0,1);
lcd.print("C:Final");
tecla = 0;
while (tecla == NULL){
tecla = teclado.getKey();
if(tecla == 'A' || tecla == 'B' || tecla == 'C' || tecla == 'D' || tecla == '*'){
opcion_selecionada = tecla;
menu_nivel = 1;
}
}
if (tecla >= '0' && tecla <= '9'){
opcion_selecionada = tecla;
menu_nivel = 1;
}
//if (tecla == '*'){
// opcion_selecionada = tecla;
// menu_nivel = 1;
//}
}
if(opcion_selecionada != ' ') {
switch(opcion_selecionada){
case 'A':
opcion_a();
break;
case 'B':
opcion_b();
break;
case 'C':
opcion_c();
break;
case 'D':
opcion_d();
break;
case '*':
inicio_ciclo();
// opcion_selecionada = ' ';
break;
default:
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("||||No Opciones||||");
delay(2000);
menu_nivel = 0;
break;
}
}
}
void opcion_a()
{
inicio = 0;
tecla = 0;
lcd.clear();
lcd.home();
lcd.print("L INICIO: ____");
lcd.setCursor(0,1);
lcd.print("'#'Aceptar");
lcd.setCursor(12,0);
while(tecla != '#'){
tecla = teclado.getKey();
if(tecla != NO_KEY){
if((tecla >= '0')&&(tecla <= '9')){
inicio = (inicio*10) + tecla - 48;
lcd.print(tecla-48);
}
}
}
menu_nivel = 0;
}
void opcion_b()
{
medio = 0;
tecla = 0;
lcd.clear();
lcd.home();
lcd.print("L MEDIO: ____");
lcd.setCursor(0,1);
lcd.print("'#'Aceptar");
lcd.setCursor(12,0);
while(tecla != '#'){
tecla = teclado.getKey();
if(tecla != NO_KEY){
if((tecla >= '0')&&(tecla <= '9')){
medio = (medio*10) + tecla - 48;
lcd.print(tecla-48);
}
}
}
menu_nivel = 0;
}
void opcion_c()
{
final = 0;
tecla = 0;
lcd.clear();
lcd.home();
lcd.print("L FINAL: ____");
lcd.setCursor(0,1);
lcd.print("'#'Aceptar");
lcd.setCursor(12,0);
while(tecla != '#'){
tecla = teclado.getKey();
if(tecla != NO_KEY){
if((tecla >= '0')&&(tecla <= '9')){
final = (final*10) + tecla - 48;
lcd.print(tecla-48);
}
}
}
menu_nivel = 0;
}
void opcion_d()
{
lcd.clear();
digitalWrite(ledW, 0);
lcd.home();
lcd.setCursor(0,0);
lcd.print("Valores: ");
lcd.setCursor(9,0);
lcd.print("I:");
lcd.setCursor(11,0);
lcd.print(inicio);
lcd.setCursor(0,1);
lcd.print("M:");
lcd.setCursor(2,1);
lcd.print(medio);
lcd.setCursor(9,1);
lcd.print("F:");
lcd.setCursor(11,1);
lcd.print(final);
delay(2000);
digitalWrite(ledW, 1);
menu_nivel = 0;
}
void inicio_ciclo()
{ lcd.setCursor(0,0);
lcd.print("||||||LED||||||");
lcd.setCursor(0,1);
lcd.print("|||||White|||||");
digitalWrite(ledW, 0);
digitalWrite(enablePinY, LOW);
stepperY.move(inicio);
stepperY.runToPosition();
digitalWrite(ledW, 1);
digitalWrite(ledW, 0);
digitalWrite(enablePinX, LOW);
stepperX.move(medio);
stepperX.runToPosition();
digitalWrite(ledW, 1);
menu_nivel = 0;
/* for (int i = 0; i < inicio; i++)
{
digitalWrite(ledW, 0);
delay(200);
digitalWrite(ledW, 1);
delay(200);
}
delay(1000);
for (int i = 0; i < medio; i++)
{
digitalWrite(ledW, 0);
delay(200);
digitalWrite(ledW, 1);
delay(200);
}
delay(1000);
for (int i = 0; i < final; i++)
{
digitalWrite(ledW, 0);
delay(200);
digitalWrite(ledW, 1);
delay(200);
}
menu_nivel = 0;
*/
}
void saludo()
{
lcd.clear();
digitalWrite(ledW, 0);
lcd.home();
lcd.setCursor(0,0);
lcd.print("Finalmente lo");
lcd.setCursor(0,1);
lcd.print("entendiste!!!!!");
delay(1000);
menu_nivel = 0;
}