DS1307 Tiny RTC I2C module - if () ?

Hi I have the DS1307 (Tiny RTC) I work this code :

#include <Wire.h>
#include “RTClib.h”
RTC_DS1307 RTC;

void setup () {
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println(“RTC is NOT running!”);
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(DATE, TIME));
}
}
void loop () {
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print(’/’);
Serial.print(now.month(), DEC);
Serial.print(’/’);
Serial.print(now.day(), DEC);
Serial.print(’ ‘);
Serial.print(now.hour(), DEC);
Serial.print(’:’);
Serial.print(now.minute(), DEC);
Serial.print(’:’);
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
}

I want to create this fuction :

If (now.hour() > 17)
{
.
.
.

}

But I take error now.hour not declare at this scope… Any help?

But I take error now.hour not declare at this scope... Any help?

You are asking questions about code you have not posted. The code you posted has no if statements in it, so they are NOT the source of the problem.

Post the ACTUAL code (in code tags, NOT quote tags) that generates the error message(s) AND the COMPLETE error messages.

#include <Wire.h>
#include “RTClib.h”
RTC_DS1307 RTC;

void setup () {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);

Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println(“RTC is NOT running!”);
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(DATE, TIME));
}
}
void loop () {
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print(’/’);
Serial.print(now.month(), DEC);
Serial.print(’/’);
Serial.print(now.day(), DEC);
Serial.print(’ ‘);
Serial.print(now.hour(), DEC);
Serial.print(’:’);
Serial.print(now.minute(), DEC);
Serial.print(’:’);
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);

If ((now.hour(), DEC) >= 17))
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);

}

If ((now.hour(), DEC) >= 17))

What do you think this is doing?

Just because Serial.print(now.hour(), DEC) makes sense does not mean that if((now.hour(), DEC) makes sense.

The value being printed is now.hour(), not now.hour(), DEC. The value to be compared is now.hour(), not now.hour(), DEC.

PaulS:

If ((now.hour(), DEC) >= 17))

What do you think this is doing?

Just because Serial.print(now.hour(), DEC) makes sense does not mean that if((now.hour(), DEC) makes sense.

The value being printed is now.hour(), not now.hour(), DEC. The value to be compared is now.hour(), not now.hour(), DEC.

I try and "now.hour()" and take the same error

hackertom:
I try and “now.hour()” and take the same error

Your code misses a closing curly brace. ‘If’ is also not correct, should be ‘if’.

And in future, please post code between [code] and [/code] so it looks like (your code)

#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;

void setup () {
    Serial.begin(9600);
 pinMode(LED_BUILTIN, OUTPUT);

    Wire.begin();
    RTC.begin();
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}
void loop () {
    DateTime now = RTC.now();
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    delay(1000);

If ((now.hour(), DEC) >= 17))
{
digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);

}

sterretje:
Your code misses a closing curly brace. ‘If’ is also not correct, should be ‘if’.

And in future, please post code between [code] and [/code] so it looks like (your code)

#include <Wire.h>

#include “RTClib.h”
RTC_DS1307 RTC;

void setup () {
    Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);

Wire.begin();
    RTC.begin();
  if (! RTC.isrunning()) {
    Serial.println(“RTC is NOT running!”);
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(DATE, TIME));
  }
}
void loop () {
    DateTime now = RTC.now();
    Serial.print(now.year(), DEC);
    Serial.print(’/’);
    Serial.print(now.month(), DEC);
    Serial.print(’/’);
    Serial.print(now.day(), DEC);
    Serial.print(’ ‘);
    Serial.print(now.hour(), DEC);
    Serial.print(’:’);
    Serial.print(now.minute(), DEC);
    Serial.print(’:’);
    Serial.print(now.second(), DEC);
    Serial.println();
    delay(1000);

If ((now.hour(), DEC) >= 17))
{
digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);

}

I don’t understand you my friend …

What don't you understand?

sterretje:
What don't you understand?

Can you help me with hour value? Or not?

Can you help me with hour value? Or not?

Mistakes have been pointed out in your code. It is not clear that you have fixed them, because you have not posted your changed code. So, no, we can't help you.