Last active
August 29, 2015 14:01
-
-
Save yamishi13/dc1a7b9fc108c28c4c9f to your computer and use it in GitHub Desktop.
Casa-domotica
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int cp = 9; | |
int ap = 8; | |
int cv = 6; | |
int av = 7; | |
int l1 = 13; | |
int l2 = 12; | |
int l3 = 11; | |
void parseSerial(String ser) { | |
//ignorar mayusculas y minusculas | |
ser.toLowerCase(); | |
if(ser == "cerrar puerta" || ser == "cerrarp") { | |
digitalWrite(cp, HIGH); | |
Serial.println("Cerrando puerta"); | |
//cantidad de tiempo en milisegundos para cerrar la puerta | |
delay(18); | |
digitalWrite(cp, LOW); | |
} else if(ser == "abrir puerta" || ser == "abrirp") { | |
digitalWrite(ap, HIGH); | |
Serial.println("Abriendo puerta"); | |
//cantidad de tiempo en milisegundos para abrir la puerta | |
delay(50); | |
digitalWrite(ap, LOW); | |
} else if(ser == "cerrar ventana" || ser == "cerrarv") { | |
digitalWrite(cv, HIGH); | |
Serial.println("Cerrando ventana"); | |
//cantidad de tiempo en milisegundos para cerrar la ventana | |
delay(100); | |
digitalWrite(cv, LOW); | |
} else if(ser == "abrir ventana" || ser == "abrirv") { | |
digitalWrite(av, HIGH); | |
Serial.println("Abriendo ventana"); | |
//cantidad de tiempo en milisegundos para abrir la ventana | |
delay(1000); | |
digitalWrite(av, LOW); | |
} else if(ser == "encender luz" || ser == "encenderl") { | |
Serial.println("Encendiendo luces"); | |
digitalWrite(l1, HIGH); | |
digitalWrite(l2, HIGH); | |
digitalWrite(l3, HIGH); | |
} else if(ser == "apagar luz" || ser == "apagarl") { | |
Serial.println("Apagando luces"); | |
digitalWrite(l1, LOW); | |
digitalWrite(l2, LOW); | |
digitalWrite(l3, LOW); | |
} else { | |
Serial.println("No se reconocio el comando"); | |
} | |
} | |
void setup() { | |
//setear puertos de salida para la puerta | |
pinMode(cp, OUTPUT); | |
pinMode(ap, OUTPUT); | |
//setear puertos de salida para la ventana | |
pinMode(cv, OUTPUT); | |
pinMode(av, OUTPUT); | |
//setear puertos de salida para los leds | |
pinMode(l1, OUTPUT); | |
pinMode(l2, OUTPUT); | |
pinMode(l3, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
//verificar que hay algo pendiente por leer en el serial | |
if(Serial.available() > 0) { | |
//juzgar la accion a realizar dependiendo el string recibido en el serial | |
parseSerial(Serial.readString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment