Bom dia
Estou em testes com o intuito de aproveitar o rtc para fazer um fade a um led ligado à porta 9 mas chega à determinada hora e ele não acende algum me ajuda a encontrar o erro ?
aqui vai o codigo
/*-----( Import needed libraries )-----*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include "RTClib.h"
/*-----( Declare Constants )-----*/
/*-----( Declare objects )-----*/
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27
/*-----( Declare Variables )-----*/
RTC_DS1307 RTC;
int led = 9; // the pin that the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
void setup() /*----( SETUP: RUNS ONCE )----*/
{
lcd.init();
lcd.backlight();
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (!RTC.isrunning())
{
RTC.adjust(DateTime(__DATE__, __TIME__));
}
pinMode(led, OUTPUT);
}
void loop()
{
DateTime agora = RTC.now();
String relogio_data = "";
String relogio_hora = "/";
int dia = agora.day();
int mes = agora.month();
int ano = agora.year();
relogio_data += ArrumaZero(dia);
relogio_data += "/";
relogio_data += ArrumaZero(mes);
relogio_data += "/";
relogio_data += ano;
int hora = agora.hour();
int minuto = agora.minute();
int segundo = agora.second();
//const int horartc = agora.hour();
if (hora >= 20 && hora < 04) digitalWrite(led, HIGH);
else digitalWrite(led, LOW);
relogio_hora += ArrumaZero(hora);
relogio_hora += ":";
relogio_hora += ArrumaZero(minuto);
lcd.setCursor(0, 0);
lcd.print(relogio_data);
lcd.print(relogio_hora);
delay(500);
}
String ArrumaZero(int i)
{
String ret;
if (i < 10) ret += "0";
ret += i;
return ret;
}