Stap 3: De Code
//Makes a signal every week at the first start of the car.<br>//It reminds you to switch on the air conditioning minimum once per week. #include #include #include int addr = 0; //EEPROM address int WN; //Week number int DOW; //Day of the Week int STORED; //Stored value in the EEPROM void setup() { Serial.begin(9600); Wire.begin(); pinMode(10, OUTPUT); //Negative output of Buzzer digitalWrite(10, LOW); pinMode(12, OUTPUT); //Positive output of Buzzer delay(100); //SET TIME //To set time need to remove the "/*" before the RTC.stopClock(); //NOTE!!! After setting time put back the "/*" and upload the program again!!! //It is important to put back "/*" and upload again. If you forget to do this, the time will be setting each starting /* RTC.stopClock(); RTC.fillByYMD(2014,10,2); RTC.fillByHMS(19,41,30); RTC.setTime(); RTC.startClock(); //*/ RTC.getTime(); //Read the date and time DOW = RTC.dow; //Day of week should be from 1 to 7 //The RTC.dow start from 0 = Sunday, 1 = Monday ... //To compensate this, you need to set Sunday = 7 in the next line if (RTC.dow == 0) //Normally Sunday is O, but in our case Sunday needs to be 7 DOW = 7; WN = ((RTC.ydn-DOW+10)/7); //Here is the date formula to determine the number of the Week STORED = EEPROM.read(addr); //Read the EEPROM if (STORED != WN){ //Here follows the signal delay(10000); //Delayed with any value Signal_aircond(); //Signal, it is on the end of the program EEPROM.write(addr, WN); //Overwrite the EEPROM with the new Week no. Serial.println("OK"); } else { // Writing to the serial monitor Serial.print(RTC.year, DEC); Serial.print('/'); if (RTC.month < 10) Serial.print("0"); Serial.print(RTC.month, DEC); Serial.print('/'); if (RTC.day < 10) Serial.print("0"); Serial.print(RTC.day, DEC); Serial.print(" "); Serial.print(RTC.hour, DEC); Serial.print(':'); if (RTC.minute < 10) Serial.print("0"); Serial.print(RTC.minute, DEC); Serial.print(" Week no.:"); Serial.print(WN); Serial.print(" Week no. in the EEPROM:"); Serial.print(EEPROM.read(addr)); Serial.print('\n'); } } void loop() { } void Signal_aircond() { tone(12,3000,500); delay(900); tone(12,3000,500); delay(900); tone(12,3000,500); }