boa noite
amigo giova 014
deu certo
com este código rtc funcionando perfeito mostrando no serial monitor, dia da semana hora minuto segundo certinho.
agora vou estudar mais sobre os dois codigos,
e tentar trazer o que eu tinha anteriormente para dentro deste.
muito obrigado até o momento.
// DS3231_Serial_Easy
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// A quick demo of how to use my DS3231-library to
// quickly send time and date information over a serial link
//
// To use the hardware I2C (TWI) interface of the Arduino you must connect
// the pins as follows:
//
// Arduino Uno/2009:
// ----------------------
// DS3231: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
// SCL pin -> Arduino Analog 5 or the dedicated SCL pin
//
// Arduino Leonardo:
// ----------------------
// DS3231: SDA pin -> Arduino Digital 2 or the dedicated SDA pin
// SCL pin -> Arduino Digital 3 or the dedicated SCL pin
//
// Arduino Mega:
// ----------------------
// DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin
//
// Arduino Due:
// ----------------------
// DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
//
// The internal pull-up resistors will be activated when using the
// hardware I2C interfaces.
//
// You can connect the DS3231 to any available pin but if you use any
// other than what is described above the library will fall back to
// a software-based, TWI-like protocol which will require exclusive access
// to the pins used, and you will also have to use appropriate, external
// pull-up resistors on the data and clock signals.
//
#include <DS3231.h>
// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);
void setup()
{
// Setup Serial connection
Serial.begin(115200);
// Uncomment the next line if you are using an Arduino Leonardo
//while (!Serial) {}
// Initialize the rtc object
rtc.begin();
// The following lines can be uncommented to set the date and time
rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014
}
void loop()
{
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
// Wait one second before repeating :)
delay (1000);
}
Giova014 como apenas você tem me ajudado me dirijo diretamente a você.
tentei de algumas maneiras resolver o caso de acionamento dos reles com a biblioteca do rtc indicada.
segue abaixo cogigo que tentei mesclando dois codigos,
pode me ajudar?
está dando mensagem de erro do "if"
não sei mais o que fazer
// DS3231_Serial_Easy
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// A quick demo of how to use my DS3231-library to
// quickly send time and date information over a serial link
//
// To use the hardware I2C (TWI) interface of the Arduino you must connect
// the pins as follows:
//
// Arduino Uno/2009:
// ----------------------
// DS3231: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
// SCL pin -> Arduino Analog 5 or the dedicated SCL pin
//
// Arduino Leonardo:
// ----------------------
// DS3231: SDA pin -> Arduino Digital 2 or the dedicated SDA pin
// SCL pin -> Arduino Digital 3 or the dedicated SCL pin
//
// Arduino Mega:
// ----------------------
// DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin
//
// Arduino Due:
// ----------------------
// DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
//
// The internal pull-up resistors will be activated when using the
// hardware I2C interfaces.
//
// You can connect the DS3231 to any available pin but if you use any
// other than what is described above the library will fall back to
// a software-based, TWI-like protocol which will require exclusive access
// to the pins used, and you will also have to use appropriate, external
// pull-up resistors on the data and clock signals.
//
#include <DS3231.h>
int segundos;
int minutos;
int horas;
int diadasemana;
int diadomes;
int mes;
int ano;
byte zero = 0x00;
int rele1 = 7;
int rele2 = 8;
int rele3 = 9;
int rele4 = 10;
bool ligarele1;
bool ligarele2;
bool ligarele3;
bool ligarele4;
// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);
void setup()
{
pinMode(rele1, OUTPUT);
digitalWrite(rele1, HIGH);
pinMode(rele2, OUTPUT);
digitalWrite(rele2, HIGH);
pinMode(rele3, OUTPUT);
digitalWrite(rele3, HIGH);
pinMode(rele4, OUTPUT);
digitalWrite(rele4, HIGH);
ligarele1 = false;
ligarele2 = false;
ligarele3 = false;
ligarele4 = false;
// Setup Serial connection
Serial.begin(115200);
// Uncomment the next line if you are using an Arduino Leonardo
//while (!Serial) {}
}
byte ConverteParaBCD(byte val){ //Converte o número de decimal para BCD
return ( (val/10*16) + (val%10) );
}
byte ConverteparaDecimal(byte val) { //Converte de BCD para decimal
return ( (val/16*10) + (val%16) );
}
void Mostrarelogio()
{
// Initialize the rtc object
rtc.begin();
// The following lines can be uncommented to set the date and time
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014
}
if ((horas >= 8) and (minutos <= 00) and (!ligarele1)) {
ligarele1 = true;
digitalWrite(rele1, LOW);}
if ((horas >= 8) and (minutos <= 30) and (!ligarele2)) {
ligarele2 = true;
digitalWrite(rele2, LOW);}
if ((horas >= 9) and (minutos <= 00) and (!ligarele3)) {
ligarele3 = true;
digitalWrite(rele3, LOW);}
if ((horas >= 9) and (minutos <= 30) and (!ligarele4)) {
ligarele4 = true;
digitalWrite(rele4, LOW);}
if ((horas >= 20) and (minutos <= 00) and (ligarele1)) {
ligarele1 = false;
digitalWrite(rele1, HIGH);}
if ((horas >= 20) and (minutos <= 30) and (ligarele2)) {
ligarele2 = false;
digitalWrite(rele2, HIGH);}
if ((horas >= 21) and (minutos <= 00) and (ligarele3)) {
ligarele3 = false;
digitalWrite(rele3, HIGH);}
if ((horas >= 21) and (minutos <= 30) and (ligarele4)) {
ligarele4 = false;
digitalWrite(rele4, HIGH);}
}
void loop()
{
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
// Wait one second before repeating :)
delay (1000);
}