Alfa75,
anche se fa schifo nell'ordine e nella sintassi questo è quello che ho buttato giù fino ad ora, se hai suggerimenti e consigli ovviamente son ben accetti
/*========================================================================== Schede Relè ======================================================================================
Variabile Accessorio Variabile
Stato Pin
R1 Pompa Mandata 1 PMand1
R2 HQI Luce 1 HQI1
R3 HQI Luce 2 HQI2
R4 Sonda Rabbocco SRab
R5 Sonda Ricambio SRic
R6 Sonda Sump SSump
R7 Pompa Mandata Skimmer PMandS
R8 Pompa Skimmer PAirSk
L1 Pompa Risalita 2 PMand2
L2 T5 Gruppo1 T5Gr1
L3 T5 Gruppo2 T5Gr2
L4 Pompa Cambio Acqua PRic
L5 Riscaldatore Sump TempS
L6 Pompa REA PRea
L7 Pompe Corrente PCorr1
L8 Pompe Corrente PCorr2
=========================================================================== Definizione Pin ==============================================================================*/
const int PMand1 = 22; //fatta
const int HQI1 = 23; //fatta
const int HQI2 = 24; //fatta
const int SRab = 25;
const int SRic = 26;
const int SSump = 27;
const int PMandS = 28;
const int PMand2= 29;
const int PAirSk = 30;
const int T5gr1 = 31;
const int T5gr2 = 32;
const int PRic = 33;
const int TempS = 34;
const int PRea = 35;
const int PCorr1 = 36;
const int PCorr2 = 37;
/*========================================================================== Definizione Stati Relay =======================================================================*/
int R1 = 0; //Pompa mandata 1
int R2 = 0; //Illuminazione HQI 1
int R3 = 0; //Illuminazione HQI 2
int R4 = 0;
int R5 = 0;
int R6 = 0;
int R7 = 0;
int R8 = 0;
int L1 = 0; //Pompa mandata 2
int L2 = 0; //Illuminazione T5 1
int L3 = 0; //Illuminazione T5 2
int L4 = 0;
int L5 = 0;
int L6 = 0;
int L7 = 0;
int L8 = 0;
int SR1, SR2; //Variabili per lo storico
/*========================================================================== Variabili di temporizzazione =======================================================================*/
int keyInput, livello, menu;
long tempo_btn = 0, debounce = 500, tempo_men = 0, ritorno; //Tempo tra due letture successive di un bottone (500 ms)
// DS1307 funzioni ora
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
int fullYear, phase, fase;
long YY, MM, K1, K2, K3, JD;
double AG, IP;
/*===============================================================================================================================================================================*/
// Definizione delle variabili temporali
int mil_time= 0;
int rol_mandata = 1; //Intervallo alternanza della pompa di mandata
int mil_mandata = 0;
/*
ALBA TRAMONTO
Accendo T5 1 Spengo HQI 1
Accendo T5 2 Spengo HQI 2
Accendo HQI 1 Spengo T5 1
Accendo HQI 2 Spengo T5 2
*/
//int alba = 30;
//int tramonto = 30;
int T5gr1_on = 32;
int T5gr2_on = 33;
int HQI1_on = 34; //Accendione lampada HQI Gruppo 1
int HQI2_on = 35; //Accendione lampada HQI Gruppo 2
int HQI1_off = 36; //Spegnimento lampada HQI Gruppo 1
int HQI2_off = 37; //Spegnimento lampada HQI Gruppo 2
int T5gr1_off = 38;
int T5gr2_off = 39;
/*========================================================================== Variabili di inclusione ============================================================================*/
#define VERSION "1.00"
#include <OneWire.h>
#include <Wire.h>
#include <DallasTemperature.h>
#include <LCDi2cR.h>
#define DS1307_I2C_ADDRESS 0x68
LCDi2cR lcd = LCDi2cR(4,40,0x63,0);
#define DS1307_I2C_ADDRESS 0x68
#define ONE_WIRE_BUS 3
#define TEMPERATURE_PRECISION 9
/*===============================================================================================================================================================================*/
/*========================================================================== configurazione temperature ===================================================================*/
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// arrays to hold device addresses
DeviceAddress Ther0, Ther1, Ther2;
/*========================================================================== configurazione rtc ============================================================================*/
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
/*===============================================================================================================================================================================*/
void setup()
{
lcd.clear();
lcd.init();
lcd.setCursor(0,5);
lcd.print("Open Reef"); // Show Version
lcd.setCursor(1,8);
lcd.print (VERSION);
keyInput=40;
menu=0;
delay(5000);
Serial.begin(9600);
int R1 = 0;
/*========================================================================== verifica setup sonde============================================================================*/
// start del monitor sotto la data
lcd.setCursor(3,0);
lcd.print("IC Control Library");
// Start up the library
sensors.begin();
// locate devices on the bus
lcd.setCursor(3,0);
//lcd.print("Locating devices...");
lcd.print("Found ");
lcd.print(sensors.getDeviceCount(), DEC);
lcd.println(" devices.");
// report parasite power requirements
lcd.setCursor(3,0);
lcd.print("ParasitePower is: ");
if (sensors.isParasitePowerMode()) lcd.print("ON");
else lcd.print("OFF");
delay(1000);
// assign address manually. the addresses below will beed to be changed
// to valid device addresses on your bus. device address can be retrieved
// by using either oneWire.search(deviceAddress) or individually via
// sensors.getAddress(deviceAddress, index)
//insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
//outsideThermometer = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };
// search for devices on the bus and assign based on an index. ideally,
// you would do this to initially discover addresses on the bus and then
// use those addresses and manually assign them (see above) once you know
// the devices on your bus (and assuming they don't change).
//
// method 1: by index
lcd.clear ();
lcd.print ("Errori rilevamento");
lcd.setCursor (1,0);
if (!sensors.getAddress(Ther0, 0)) lcd.print ("Non rilevato Device0");
lcd.setCursor (2,0);
if (!sensors.getAddress(Ther1, 1)) lcd.print ("Non rilevato Device1");
lcd.setCursor (3,0);
if (!sensors.getAddress(Ther2, 2)) lcd.print ("Non rilevato Device2");
// Definiamo la funzione dei pin
pinMode(PMand1, OUTPUT);
pinMode(HQI1, OUTPUT);
pinMode(HQI2, OUTPUT);
pinMode(SRab, OUTPUT);
pinMode(SRic, OUTPUT);
pinMode(SSump, OUTPUT);
pinMode(PMandS, OUTPUT);
pinMode(PAirSk, OUTPUT);
pinMode(PMand2, OUTPUT);
pinMode(T5gr1, OUTPUT);
pinMode(T5gr2, OUTPUT);
pinMode(PRic, OUTPUT);
pinMode(TempS, OUTPUT);
pinMode(PRea, OUTPUT);
pinMode(PCorr1, OUTPUT);
pinMode(PCorr2, OUTPUT);
//delay (1000);