Sunteți pe pagina 1din 3

#include <SoftwareSerial.

h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Key.h>

const byte ROWS = 4; //four rows


const byte COLS = 4; //four columns
char keys[ROWS][COLS] = { //create keypad mapping
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};

byte rowPins[ROWS] = {13, 12, 11, 10}; // connect to the row pinout of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; // connect to the column pinout of the keypad

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

char key;
char prev_key;
long temp;

#define LUZ1 5
#define LUZ2 4
#define LUZ3 3

// initialize the library with the numbers of the interface pins


LiquidCrystal lcd(48, 49, 50, 51, 52, 53);

void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
pinMode(LUZ1, OUTPUT);
pinMode(LUZ2, OUTPUT);
pinMode(LUZ3, OUTPUT);
inicio();
}

void loop() {
// put your main code here, to run repeatedly:
key = kpd.getKey();
if(key != NO_KEY){
switch (key) {
case 'A':
//secuencia A
lcd.clear();
lcd.print("Opcion A elegida");
semaforo(10000, 5000, 10000);
break;
case 'B':
//secuencia B
lcd.clear();
lcd.print("Opcion B elegida");
semaforo(15000, 10000, 15000);
break;
case 'C':
//secuencia C
lcd.clear();
lcd.print("Opcion C elegida");
semaforo(20000, 15000, 20000);
break;
case 'D':
//secuencia D
abortar:
digitalWrite(LUZ1, LOW);
digitalWrite(LUZ2, LOW);
digitalWrite(LUZ3, LOW);
lcd.clear();
lcd.print("Opcion D elegida");
lcd.setCursor(0,1);
lcd.print("Detenido!");
break;
default:
//cualquier otro boton
lcd.clear();
lcd.print("Seleccion");
lcd.setCursor(0,1);
lcd.print("invalida!");
delay(1000);
key = NO_KEY;
inicio();
break;
}
}
}

void semaforo(long tiempo1, long tiempo2, long tiempo3) {


temp = 100;
do {
key = kpd.getKey();
if (key == 'D') {
goto abortar2;
}
digitalWrite(LUZ1, HIGH);
delay(100);
temp = temp + 100;
} while ( temp <= tiempo1 );
digitalWrite(LUZ1, LOW);
temp = 100;
do {
key = kpd.getKey();
if (key == 'D') {
goto abortar2;
}
digitalWrite(LUZ2, HIGH);
delay(100);
temp = temp + 100;
} while ( temp <= tiempo2 );
digitalWrite(LUZ2, LOW);
temp = 100;
do {
key = kpd.getKey();
if (key == 'D') {
goto abortar2;
}
digitalWrite(LUZ3, HIGH);
delay(100);
temp = temp + 100;
} while ( temp <= tiempo3 );
digitalWrite(LUZ3, LOW);
abortar2:
digitalWrite(LUZ1, LOW);
digitalWrite(LUZ2, LOW);
digitalWrite(LUZ3, LOW);
}

void inicio() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Seleccione una");
lcd.setCursor(0,1);
lcd.print("opcion: A,B,C");
}

S-ar putea să vă placă și