void SettingsDateMenu::button2() { if (selection == 6) { switchMenu(MENU_SETTINGS); } else { uint16_t year = state.now.year(); uint8_t month = state.now.month(); uint8_t day = state.now.day(); if (selection == 2) { year += 1; } else if (selection == 5) { year -= 1; } else if (selection == 1) { month = (month % 12) + 1; } else if (selection == 4) { month = month == 1 ? 12 : (month - 1); } else if (selection == 0) { day = (day % 31) + 1; } else if (selection == 3) { day = day == 1 ? 31 : (day - 1); } state.now = DateTime(year, month, day, state.now.hour(), state.now.minute(), state.now.second()); state.timeUpdated = true; state.timeMinuteUpdated = true; RTC.adjust(state.now); } }
/** Ensures rtc is adjusted to correct time. */ void Clock::startRtc(){ if(!rtc.isrunning()){ Serial.println("Time set to compiletime"); rtc.adjust(DateTime(__DATE__, __TIME__)); }else{ Serial.println("Time was NOT ADJUSTED"); } }
void ClockTime::setup(){ RTC.begin(); // begin clock 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__)); } }
bool setRTC() { Wire.begin(); RTC.begin(); // Sets RTC to the date & time sketch was compiled RTC.adjust(DateTime(__DATE__, __TIME__)); return true; }
static int modbus_after_write_table(struct modbus_instance *instance, enum modbus_table table, uint16_t address, uint16_t count) { if (table == MODBUS_TABLE_HOLDING_REGISTERS) { uint16_t offset = ELEMENT_OFFSET(common_values, now); if (ELEMENT_IN(0x0000, offset, address * 2, count * 2)) { // SYNC CLOCK DateTime dt(common_values.now.year, common_values.now.month, common_values.now.day, common_values.now.hours, common_values.now.minutes, common_values.now.seconds); OS::TSysTimerLocker lock; RTC_DS1307 rtc; rtc.begin(); rtc.adjust(dt); } offset = ELEMENT_OFFSET(common_values, modbus_address); if (ELEMENT_IN(0x0000, offset, address * 2, count * 2)) { config_lock(); config_set_address(common_values.modbus_address & 0xFF); config_unlock(); // instance->address = common_values.modbus_address; } } if (table == MODBUS_TABLE_COILS) { uint16_t offset = ELEMENT_OFFSET(controls, restart_programs); if (ELEMENT_IN(0x0000, offset, address, count)) { if (controls.restart_programs == 0x01) { controls.restart_programs = 0x00; controls.pause_flag = 0x00; program_reset(); config_set_pause_flag(controls.pause_flag); } } offset = ELEMENT_OFFSET(controls, pause_flag); if (ELEMENT_IN(0x0000, offset, address, count)) { config_set_pause_flag(controls.pause_flag); } } MODBUS_RETURN(instance, MODBUS_SUCCESS); }
// Init the RTC void ClockMaster::initRTC(){ //Wire.pins(2, 14); // SDA an SCL (comment on this, source is RTCLib::ds1307 // Start RTC, print error if it's not found if (!rtc.begin()) { Serial.println("Couldn't find RTC"); while (1); } if (!rtc.isrunning()) { // following line sets the RTC to the date & time this sketch was compiled rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); Serial.println("RTC time set to compile-date"); } }
void setup () { Serial.begin(9600); Wire.begin(); rtc.begin(); if (! rtc.isrunning()) { Serial.println("RTC is NOT running!"); rtc.adjust(DateTime(2014,02,16,14,45,00)); // following line sets the RTC to the date & time this sketch was compiled //rtc.adjust(DateTime(__DATE__, __TIME__)); } }
void AgroShield::setDateTime(){ Wire.begin(); RTC.begin(); if (! RTC.isrunning()) { Serial.println("RTC is NOT running..."); } // This section grabs the current datetime and compares it to // the compilation time. If necessary, the RTC is updated. DateTime now = RTC.now(); DateTime compiled = DateTime(__DATE__, __TIME__); if (now.unixtime() < compiled.unixtime() || now.unixtime() > compiled.unixtime()) { Serial.println("RTC is older than compile time! Updating"); RTC.adjust(DateTime(__DATE__, __TIME__)); } Serial.println("Setup complete."); delay(100); }
void setup() { // debugging channel Serial1.begin(57600); while (!Serial1) { delay(100); } Serial1.print( "RAM at setup " ); Serial1.println( freeRam() ); // ALRAM pinMode(ALARM_LED_PIN, OUTPUT); digitalWrite( ALARM_LED_PIN, LOW ); // must "begin" the button to get proper pin assignment/muxing b.begin(); // initializing ADC channels. The channels 0...7 are assigned to the // pins A0...A7. Note that the display and the config.txt files, as well as // the shield's silk layer use enumeration 1 to 8 ADCs[0] = AdcChannel(A0); ADCs[1] = AdcChannel(A1); ADCs[2] = AdcChannel(A2); ADCs[3] = AdcChannel(A3); ADCs[4] = AdcChannel(A4); ADCs[5] = AdcChannel(A5); ADCs[6] = AdcChannel(A6); ADCs[7] = AdcChannel(A7); // initializing actuators. The Id is 0 to 7, a bit number in // actuator byte of the ADC channel. The mapping to the pin is // pin = A8 + Id Actuators[0] = Actuator(0, true); Actuators[1] = Actuator(1, true); Actuators[2] = Actuator(2, true); Actuators[3] = Actuator(3, true); Actuators[4] = Actuator(4, true); Actuators[5] = Actuator(5, true); Actuators[6] = Actuator(6, true); Actuators[7] = Actuator(7, false); // the last actuator is not connected through ULN2003 but directly // The Real Time Clock rtc.begin(); // returns bool, but is never false Serial1.print( "RAM after rtc.begin " ); Serial1.println( freeRam() ); if(rtc.isrunning()) Serial1.println("RTC is running"); else { Serial1.println("RTC is NOT running"); rtc.adjust(DateTime(__DATE__, __TIME__)); // setup the current date and time initially } DateTime now = rtc.now(); Serial1.print(now.year(), DEC); Serial1.print('/'); Serial1.print(now.month(), DEC); Serial1.print('/'); Serial1.print(now.day(), DEC); Serial1.print(" ("); Serial1.print(daysOfTheWeek[now.dayOfTheWeek()]); Serial1.print(") "); Serial1.print(now.hour(), DEC); Serial1.print(':'); Serial1.print(now.minute(), DEC); Serial1.print(':'); Serial1.print(now.second(), DEC); Serial1.println(); // activate LCD module lcd.begin (16,2); // for 16 x 2 LCD module lcd.setBacklightPin(3,POSITIVE); lcd.setBacklight(HIGH); Serial1.print( "RAM after lcd.begin " ); Serial1.println( freeRam() ); if(!Store.begin()) { Serial1.println("Error initializing the storage"); digitalWrite( ALARM_LED_PIN, HIGH ); } Serial1.print( "RAM after Storage.begin " ); Serial1.println( freeRam() ); // the below makes sure the 1st active item is displayed upon start up. Otherwise // the item 0 is displayed, even if inactive Store.mIndex = CHANNEL_COUNT-1; Store.Advance(); }
void OpenGardenClass::setTime(void){ RTC.adjust(DateTime(__DATE__, __TIME__)); }
void AgroShield::getDateTime(){ boolean run = true; Wire.begin(); RTC.begin(); if (! RTC.isrunning()) { Serial.print("RTC is NOT running | "); run = false; } if(run){ // This section grabs the current datetime and compares it to // the compilation time. If necessary, the RTC is updated. DateTime now = RTC.now(); DateTime compiled = DateTime(__DATE__, __TIME__); //if (now.unixtime() < compiled.unixtime() || now.unixtime() > compiled.unixtime()) { if (now.unixtime() < compiled.unixtime() ) { //Serial.println("RTC is older than compile time! Updating"); RTC.adjust(DateTime(__DATE__, __TIME__)); } //Serial.println("Setup complete."); delay(100); // Get the current time now = RTC.now(); // Display the current time //Serial.print("Current time: "); if (now.day() <= 9) { Serial.print("0"); Serial.print(now.day(), DEC); } else{ Serial.print(now.day(), DEC); } Serial.print('/'); if (now.month() <= 9) { Serial.print("0"); Serial.print(now.month(), DEC); } else{ Serial.print(now.month(), DEC); } Serial.print('/'); Serial.print(now.year(), DEC); Serial.print(' '); if (now.hour() <= 9) { Serial.print("0"); Serial.print(now.hour(), DEC); } else{ Serial.print(now.hour(), DEC); } Serial.print(':'); if (now.minute() <= 9) { Serial.print("0"); Serial.print(now.minute(), DEC); } else{ Serial.print(now.minute(), DEC); } Serial.print(':'); if (now.second() <= 9) { Serial.print("0"); Serial.print(now.second(), DEC); Serial.print(" | "); } else{ Serial.print(now.second(), DEC); Serial.print(" | "); } delay(100); } }
void setDateTime(char date[], char time[]) { RTC.adjust(DateTime(date, time)); }
void Cron::setTime(DateTime time){ RTC.adjust(time); }
void setup(void) { status.reset(); /// Discrete & Analog IO pinMode(13, OUTPUT); // Arduino on-board LED pinMode(A0, OUTPUT); // Buzzer /// Comm. Channels // UART Serial.begin(115200); Serial.flush(); Serial.println("Starting up greenOmatic Duemilanove Testbed..."); Serial.print("Program compiled on "); Serial.print(__DATE__); Serial.print(" at "); Serial.println(__TIME__); Serial.println(); // RF #ifdef INTERFACE_ASK_RX pinMode(RF_RX_PIN, INPUT); vw_set_rx_pin(RF_RX_PIN); vw_setup(RF_BAUD); vw_rx_start (); Serial.print ("ASK RF Receiver configured on PIN "); Serial.print (RF_RX_PIN); Serial.print (" @ "); Serial.print (RF_BAUD, DEC); Serial.println(" baud."); #endif //INTERFACE_ASK_RX // Ethernet #ifdef INTERFACE_ETHERNET Serial.print("Starting Ethernet... "); #ifdef ETHERNET_DYNAMIC_IP int eth_stat = Ethernet.begin(mac); if (0 == eth_stat) { Serial.println(" Problem starting ethernet !"); status.ethernet_valid = status.ERROR; } else { Serial.print("Ethernet started, IP = "); Serial.println( Ethernet.localIP() ); status.ethernet_valid = status.VALID; } #else Ethernet.begin(mac, IPaddr); Serial.print("Ethernet started, IP = "); Serial.println( Ethernet.localIP() ); status.ethernet_valid = status.VALID; #endif //ETHERNET_DYNAMIC_IP #ifdef ETHERNET_WEBSERVER server.begin(); #endif //ETHERNET_WEBSERVER #ifdef ETHERNET_UDPCLIENT Udp.begin(localPort); #endif //ETHERNET_UDPCLIENT #endif /// Peripherals // I2C RTC #ifdef PERIPHERAL_RTCC Wire.begin(); rtc.begin(); if (rtc.isrunning()) { status.time_valid = status.VALID; GetDatetimeString(rtc.now()); Serial.print("RTCC configured on I2C. Time is currently "); Serial.println(currentTime); #ifdef ETHERNET_UDPCLIENT //TODO: Get NTP Time #else // Compare RTC time to this programs compile time DateTime rtcTime = rtc.now(); DateTime compileTime(F(__DATE__), F(__TIME__)); // If the compile-time is later (more recent) than the current RTC time, update the RTC if (compileTime.secondstime() > rtcTime.secondstime()) { Serial.println("Program compile-time is later than RTC time; updating RTC."); rtc.adjust( DateTime(F(__DATE__), F(__TIME__)) ); } #endif //ETHERNET_UDPCLIENT } else { status.time_valid = status.ERROR; // TODO, can we narrow this down further like with the DS1307RTC library? } #endif Serial.println("\nInitialization complete!\n\n"); }