DS1307 (clock)

Ciao,
sono una studentessa di disegno industriale alle prime prese con Arduino.
Ho comprato il Chip DS1307: http://www.robot-italy.com/product_info.php?products_id=763
Vorrei che si accendesse il led quando mi segnala una determinata ora di un determinato giorno, ma forse sbaglio completamente la programmazione. Lo sketch è:

#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h> // written by  mattt on the Arduino forum and modified by D. Sjunnesson
#include <Servo.h>

const int ledPin =  11;

int ledState = LOW;
long previousMillis = 0;

long interval = 1000; 

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

  RTC.stop();
  RTC.set(DS1307_SEC,1);        //set the seconds
  RTC.set(DS1307_MIN,05);     //set the minutes
  RTC.set(DS1307_HR,13);       //set the hours
  RTC.set(DS1307_DOW,5);       //set the day of the week
  RTC.set(DS1307_DATE,23);       //set the date
  RTC.set(DS1307_MTH,10);        //set the month
  RTC.set(DS1307_YR,9);         //set the year
  RTC.start();

}

void loop()
{

  Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  Serial.print(":");
  Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  Serial.print(":");
  Serial.print(RTC.get(DS1307_SEC,false));//read seconds
  Serial.print("      ");                 // some space for a more happy life
  Serial.print(RTC.get(DS1307_DATE,false));//read date
  Serial.print("/");
  Serial.print(RTC.get(DS1307_MTH,false));//read month
  Serial.print("/");
  Serial.print(RTC.get(DS1307_YR,false)); //read year
  Serial.println();

  delay(1000);

 
if ((DS1307_YR == 9) && (DS1307_MTH == 10) && (DS1307_DATE == 23) && (DS1307_HR == 13) && (DS1307_MIN == 06) && (DS1307_SEC >= 1) && (DS1307_SEC <=3 ) )
    {  if (millis() - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = millis();   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
      
    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
      
          }
     delay(3000); //qui attende 3 secondi in modo tale che il clock vada avanti e non entri + in questo ciclo
    }
}

Sorry again , here's the translation
I am a student of industrial design in the first grips with Arduino.
I bought the chip DS1307:
http://www.robot-italy.com/product_info.php?products_id=763
I would program such alarm: when it comes time to maturity should turn on the LED, but I can not.
maybe completely wrong programming.

The code:-
(DS1307_SEC >= 1) && (DS1307_SEC <=3 )
is open for only 1 second, then

delay(3000);

Waits 3 seconds, so you have a chance of missing the open window.


QUOTE:
The code:-
(DS1307_SEC >= 1) && (DS1307_SEC <=3 )
is open for only 1 second, then

delay(3000);

Waits 3 seconds, so you have a chance of missing the open window.


Sorry but I can't understand.. Delay is already written .. no? :-/

Is possible to use this ds1307 as an alarm?

Yes, it is.

DS1307_YR, DS1307_MTH, atc. are constants, not variables. The Serial.print statements call RTC.get() with those constants, and write out the results. But, you never call RTC.get and save the value.

The long if test you have is checking to see if the constants match some values, which, of course, they do not.

You need to create some variables to hold the time values, populate those variables, and compare those variables to the time of interest to you.

How do I create those variables, and what do you mean with "populate" the variables?Can you please write down a short code example?
Sorry but I've just started to use Arduino.
Thanks :slight_smile:

You create a variable like this:

int hr;

You populate, or assign a value to it, like this:

hr = RTC.get(DS1307_HR,true);