Ya tengo codigo, pero tendre que pulirlo un poco a dnd van conectados los pins y el lcd en serie lo tengo que modificar porque el q sale no es el mismo que el mio que es 2004 en serie. Ah!!! lo que tampoco me sale es el ethernet para mirar parametros y modificar por ejemplo : apagar alguna bomba remotamente...
Haber si me ayudais con el codigo por si esta bien o mal!!
/////////////////////////////////////////////// //Importamos las librerias necesarias: ///////////////////////////////////////////////
#include <LiquidCrystal.h> //LCD
#include <OneWire.h> //temperatura
#include <DallasTemperature.h>//temperatura
#include <Wire.h>
/////////////////////////////////////////////// //Definimos las constantes: ///////////////////////////////////////////////
#define ONE_WIRE_BUS 7 //temperatura, pin de entrada
#define DS1307_I2C_ADDRESS 0x68 //Reloj
#define ANCHOLCD 20 //Ancho del lcd
#define ALTOLCD 4 //Alto del lcd ///////////////////////////////////////////////
//Creamos las clases necesarias: ///////////////////////////////////////////////
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
//LCD OneWire oneWire(ONE_WIRE_BUS);
//temperatura DallasTemperature sensors(&oneWire);
//temperatura ///////////////////////////////////////////////
//Creamos las variables que vamos a usar: ///////////////////////////////////////////////
byte ledcontrolv = 13; //led control byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
RELOJ int Retraso=5000;
// Pines de los relés:
int PinAzules = 2;
//primarias//
int PinBlancas = 4;
//secundarias// ////////////////////////////////////////////////////////////////////////////////////
// // SETUP // ////////////////////////////////////////////////////////////////////////////////////
void setup() { Wire.begin();
RELOJ pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode (ledcontrolv, OUTPUT);//leds control
pinMode(PinAzules, OUTPUT); //Luces primarias
pinMode(PinBlancas, OUTPUT); //Luces secundarias
lcd.begin(ANCHOLCD,ALTOLCD);
LCD Serial.begin(9600);
// Comunicaciones con el ordenador ???????????????????
sensors.begin();
//Temperatura // si desea poner en hora, active esta parte y luego vuelva a quitarla /*
second = 0;
minute = 55;
hour = 16;
dayOfWeek = 6;
dayOfMonth = 29;
month = 9;
year = 12;
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
delay(1000); //Espera de un segundo ????????????????? }
//////////////////////////////////////////////////////////////////////////////////// // // BUCLE PRINCIPAL // ////////////////////////////////////////////////////////////////////////////////////
void loop () { getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
// LEEMOS LA HORA
if (minute < 2) Retraso=1000;
else if (hour < 5) Retraso=10000;
else Retraso=2500;
Luces(minute, hour);
}
//////////////////////////////////////////////////////////////// // FUNCIONES PRINCIPALES ////////////////////////////////////////////////////////////////
void Luces(int minutos, int horas) {
primarias
int LucesAzules;
int InicioAmanecerAzul=800;
//13:30=800//
int FinAmanecerAzul=924;
//15:40=924//
int InicioAnochecerAzul=1375;
//22:55=1375//
int FinAnochecerAzul=1440;
//00:00=1440//
int FinLuzLuna=120;
//2:00=120//
int MaxAzul=250;
int PorcentAzules;
//secundarias//
int LucesBlancas;
int InicioAmanecerBlancas=1020;
//18:00=1080//
int FinAmanecerBlancas=1083;
//19;03=1143//
int InicioAnochecerBlancas=1318;//21:58=1318//
int FinAnochecerBlancas=1380;
//23:00=1380//
int MaxBlancas=250;
int PorcentBlancas;
int Tiempo; Tiempo=horas*60+minutos;
Tiempo=Tiempo+60;
Horario de Verano
//################################# primarias ################################### //
Luna if (Tiempo <= FinLuzLuna) LucesAzules=map(Tiempo,0,FinLuzLuna, FinLuzLuna,0);
//Noche if (Tiempo < InicioAmanecerAzul && Tiempo > FinLuzLuna)
LucesAzules=0; //Amanecer if (Tiempo >= InicioAmanecerAzul && Tiempo <= FinAmanecerAzul)
LucesAzules=map(Tiempo, InicioAmanecerAzul, FinAmanecerAzul, 0, MaxAzul);
//Dia if ((Tiempo > FinAmanecerAzul) && (Tiempo < InicioAnochecerAzul))
LucesAzules=MaxAzul;
//Anochecer if (Tiempo >= InicioAnochecerAzul && Tiempo <= FinAnochecerAzul)
LucesAzules=map(Tiempo, InicioAnochecerAzul, FinAnochecerAzul, MaxAzul, FinLuzLuna );
//Control if( LucesAzules <0) LucesAzules=0; if( LucesAzules >MaxAzul)
LucesAzules=MaxAzul;
//################################# secundarias ################################### //
Noche if (Tiempo < InicioAmanecerBlancas) LucesBlancas=0;
//Amanecer if (Tiempo >= InicioAmanecerBlancas && Tiempo <= FinAmanecerBlancas)
LucesBlancas=map(Tiempo, InicioAmanecerBlancas, FinAmanecerBlancas, 0, MaxBlancas);
//Dia if (Tiempo > FinAmanecerBlancas && Tiempo < InicioAnochecerBlancas)
LucesBlancas=MaxBlancas;
//Anochecer if (Tiempo >= InicioAnochecerBlancas && Tiempo <= FinAnochecerBlancas)
LucesBlancas=map(Tiempo, InicioAnochecerBlancas, FinAnochecerBlancas, MaxBlancas, 0 );
//Control if( LucesBlancas <0)
LucesBlancas=0;
if( LucesBlancas >MaxBlancas) LucesBlancas=MaxBlancas;
//funciones de reles if (LucesAzules >= 1){
digitalWrite(PinAzules, LOW);
}else{ digitalWrite(PinAzules, HIGH);
} if (LucesBlancas >= 1){ digitalWrite(PinBlancas, LOW);
}else{ digitalWrite(PinBlancas, HIGH);
} analogWrite(9, 255-LucesAzules );
analogWrite(10, 255-LucesBlancas);
PorcentAzules =Porcent(LucesAzules ,255);
PorcentBlancas=Porcent(LucesBlancas ,255);
p();
Lcdini();
lcd.setCursor(0,0);
lcd.print(" ILUMINACION ");
lcd.setCursor(0,1);
lcd.print("****************");
p();
p();
Lcdini();
lcd.setCursor(0,0);
lcd.print(" LUCES PRIMARIAS");
lcd.setCursor(0,1);
if (PorcentAzules < 10) lcd.print("0");
lcd.print(PorcentAzules);
lcd.print("% ");
p();
// Pausa 3 segundos
Lcdini();
lcd.setCursor(0,0);
lcd.print(" LUCES SECUNDARIAS");
lcd.setCursor(0,1);
if (PorcentBlancas < 10) lcd.print("0");
lcd.print(PorcentBlancas);
lcd.print("% ");
p();
// Pausa 3 segundos
Lcdini();
lcd.setCursor(0,0);
if (LucesAzules+LucesBlancas > 1) lcd.print(" ILUMINACION ON ");
else lcd.print(" ILUMINACION OFF ");
p();
//Nombre proyecto ???????????????????????????????
Lcdini();
lcd.setCursor(0,0);
lcd.print("Morfeo REEF");
lcd.setCursor(0,1);
lcd.print("VER. 1.0");
p();
// Pausa 3 segundos
ledvoff();//Apagamos led control
p();
// Pausa 3 segundos
ledvon();
//Encendemos led control
Lcdini();
lcd.setCursor(0,0);
lcd.print(" HORA & FECHA ");
lcd.setCursor(0,1);
lcd.print("****************");
p();
// Pausa 3 segundos // ahora mostrar fecha y hora
Lcdini();
lcd.setCursor(0,0);
lcd.print("Hora: ");
if (hour < 10) lcd.print("0");
lcd.print(hour, DEC);
lcd.print(":");
if (minute < 10) lcd.print("0");
lcd.print(minute, DEC);
lcd.setCursor(0,1);
switch (dayOfWeek) { case 1: lcd.print("Lun , ");
break;
case 2: lcd.print("Mar , ");
break;
case 3: lcd.print("Mie , ");
break;
case 4: lcd.print("Jue , ");
break;
case 5: lcd.print("Vie , ");
break;
case 6: lcd.print("Sab , ");
break;
case 7: lcd.print("Dom , ");
break;
}
lcd.print(dayOfMonth, DEC);
lcd.print("/");
lcd.print(month, DEC);
lcd.print("/"); lcd.print("20");
if (year < 10) lcd.print("0");
Serial.print(year, DEC);
p();
// Pausa 3 segundos
p();
// Pausa 3 segundos
Lcdini();
lcd.setCursor(0,0);
lcd.print(" TEMPERATURAS ");
lcd.setCursor(0,1);
lcd.print("****************");
p();
//???????????????????????????? HAY QUE COMPROBAR ESTA PARTE ??????????????????????????
Lcdini();
sensors.requestTemperatures();
lcd.print("T. CUADRO: ");
lcd.print(sensors.getTempCByIndex(0));
//Index 0 , es el primer sensor
lcd.print("\337C");
p();
// Pausa 3 segundos
Lcdini();
lcd.setCursor(0,0);
lcd.print("T. ACUARIO: ");
Serial.print(sensors.getTempCByIndex(1)); // Index 1, es el 2º sensor del cable
lcd.print("\337C");
p();
// Pausa 3 segundos } ////////////////////////////////////////////////////////////////
// FUNCIONES AUXILIARES ////////////////////////////////////////////////////////////////
// Establece la fecha y el tiempo del ds1307:
void getDateDs1307( byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year) {
// Resetea el registro puntero:
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7); // Alguno de estos necesitan enmascarar porque ciertos bits son bits de control :
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read()); }
//////////////// PORCENTAJE : int Porcent(int Valor, int Maximo)
{ int result; result=Valor*100; result=result/Maximo; return result;
} //Iniciar LCD:
void Lcdini () { lcd.display();
lcd.clear();
} //Apagar LCD:
void lcdoff() { lcd.noDisplay();
} // Pausa 3 segundos: void p () { delay (3000); }
//Enciende el led control v:
void ledvon() { digitalWrite (ledcontrolv, HIGH);
} //Apaga el led control v:
void ledvoff() { digitalWrite (ledcontrolv, LOW); }
//Pasa de decimal a hexadecimal:
byte decToBcd(byte val)
//RELOJ
{ return ( (val/10*16) + (val%10) ); } // pasa de hexadecimal a decimal:
byte bcdToDec(byte val){ return ( (val/16*10) + (val%16) );
}