Created
November 1, 2017 01:18
-
-
Save HectorTorres/7a0185b52d0a61d018a3ee2a739971ed to your computer and use it in GitHub Desktop.
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
#include <Time.h> | |
#include <TimeLib.h> | |
#include <OneWire.h> | |
#include "max6675.h" | |
float temperatura=0; //Se crea una variable flotante para almacenar la temperatura | |
//Se definen los pines a usar para conectar el módulo MAX6675 | |
int ktcSO = 11; | |
int ktcCS = 12; | |
int ktcCLK = 13; | |
MAX6675 ktc(ktcCLK, ktcCS, ktcSO); | |
//alarma. | |
int duracion=250; //duracion del sonido | |
int fMin=2000; //frecuencia mas baja | |
int fMax=4000; //frecuencia mas alta | |
int i=0; | |
// declaracion de pines y variabls. | |
Int foco= 10; // pin de salida del foco. | |
int alarma = 9 ;// pin de salida de la alarma. | |
Int star = 8; //led indicador de comienzo de conteo | |
void setup() { | |
//activa comunicacion serial. | |
Serial.begin(9600); | |
delay(500); | |
//decalracion de boton. | |
Serial.begin(9600); | |
//configure pin2 as an input and enable the internal pull-up resistor | |
pinMode(10, INPUT_PULLUP); | |
//Anotamos la hora y la fecha desde la que nuestro programa empezará a contar. | |
//Formato: hora, minutos, segundos, días, mes, año | |
setTime(12,00,00,25,8,2017); | |
pinMode(foco, OUTPUT); | |
pinMode (alarma, OUTPUT); | |
} | |
void loop() { | |
//Leer temperatura. | |
temperatura=ktc.readCelsius(); | |
//temperatura=ktc.readFahrenheit(); | |
//Enviar dato de temperatura por el puerto serial. | |
Serial.print("Temperatura = "); | |
Serial.print(temperatura); | |
Serial.println(" C"); | |
//Pausa de medio segundo para repetir el proceso | |
delay(500); | |
//read the pushbutton value into a variable | |
int sensorVal = digitalRead(7); | |
//print out the value of the pushbutton | |
Serial.println(sensorVal); | |
setTime(12,1,00,25,8,2017); | |
if(temperatura>=30 && temperatura<=40) | |
{ | |
digitalWrite(star,HIGH); | |
while(temperatura>=-127 && temperatura<=127 && sensorVal==HIGH) | |
{ | |
time_t t = now();//Declaramos la variable time_t t | |
//Imprimimos la fecha y lahora | |
Serial.print(day(t)); | |
Serial.print(+ "/") ; | |
Serial.print(month(t)); | |
Serial.print(+ "/") ; | |
Serial.print(year(t)); | |
Serial.print( " ") ; | |
Serial.print(hour(t)); | |
Serial.print(+ ":") ; | |
Serial.print(minute(t)); | |
Serial.print(":") ; | |
Serial.println(second(t)); | |
delay(1000);//Esperamos 1 segundo | |
//read the pushbutton value into a variable | |
int sensorVal = digitalRead(7); | |
//print out the value of the pushbutton | |
Serial.println(sensorVal); | |
//Programamos la hora a la que la alarma se activará | |
if(hour(t)==20 && sensorVal==HIGH) | |
{ | |
digitalWrite(foco,HIGH); | |
digitalWrite(alarma,HIGH); | |
//sonido mas agudo | |
for (i=fMin;i<=fMax;i++) | |
tone (alarma,i,duracion); | |
//sonido mas grave | |
for (i=fMax;i>=fMin;i--) | |
tone (alarma,i,duracion); | |
} | |
else | |
{ | |
digitalWrite(alarma,LOW); | |
digitalWrite(foco,LOW); | |
} | |
if(sensorVal==LOW){ | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment