#include"RTC.h"voidsetup(){Serial.begin(9600);RTC.begin();RTCTimestartTime(30,Month::JUNE,2023,13,37,00,DayOfWeek::WEDNESDAY,SaveLight::SAVING_TIME_ACTIVE);RTC.setTime(startTime);}voidloop(){RTCTimecurrentTime;// Get current time from RTC
RTC.getTime(currentTime);}
#include"RTC.h"voidsetup(){Serial.begin(9600);RTC.begin();RTCTimestartTime(30,Month::JUNE,2023,13,37,00,DayOfWeek::WEDNESDAY,SaveLight::SAVING_TIME_ACTIVE);RTC.setTime(startTime);}voidloop(){RTCTimecurrentTime;// Get current time from RTC
RTC.getTime(currentTime);// Print out date (DD/MM//YYYY)
Serial.print(currentTime.getDayOfMonth());Serial.print("/");Serial.print(Month2int(currentTime.getMonth()));Serial.print("/");Serial.print(currentTime.getYear());Serial.print(" - ");// Print time (HH/MM/SS)
Serial.print(currentTime.getHour());Serial.print(":");Serial.print(currentTime.getMinutes());Serial.print(":");Serial.println(currentTime.getSeconds());delay(1000);}
#include"RTC.h"voidsetup(){Serial.begin(9600);RTC.begin();RTCTimestartTime(30,Month::JUNE,2023,13,37,00,DayOfWeek::WEDNESDAY,SaveLight::SAVING_TIME_ACTIVE);RTC.setTime(startTime);}voidloop(){RTCTimecurrentTime;// Get current time from RTC
RTC.getTime(currentTime);//Unix timestamp
Serial.print("Unix timestamp: ");Serial.println(currentTime.getUnixTime());delay(1000);}
#include"RTC.h"volatileboolirqFlag=false;volatileboolledState=false;constintled=LED_BUILTIN;voidsetup(){pinMode(led,OUTPUT);Serial.begin(9600);// Initialize the RTC
RTC.begin();// RTC.setTime() must be called for RTC.setPeriodicCallback to work, but it doesn't matter
// what date and time it's set to
RTCTimemytime(30,Month::JUNE,2023,13,37,00,DayOfWeek::WEDNESDAY,SaveLight::SAVING_TIME_ACTIVE);RTC.setTime(mytime);if(!RTC.setPeriodicCallback(periodicCallback,Period::ONCE_EVERY_2_SEC)){Serial.println("ERROR: periodic callback not set");}}voidloop(){if(irqFlag){Serial.println("Timed CallBack");ledState=!ledState;digitalWrite(LED_BUILTIN,ledState);irqFlag=false;}}voidperiodicCallback(){irqFlag=true;}
unsignedlongpreviousMillis=0;constlonginterval=1000;boolledState=false;// Include the RTC library
#include"RTC.h"voidsetup(){//initialize Serial Communication
Serial.begin(9600);//define LED as output
pinMode(LED_BUILTIN,OUTPUT);// Initialize the RTC
RTC.begin();// RTC.setTime() must be called for RTC.setAlarmCallback to work, but it doesn't matter
// what date and time it's set to in this example
RTCTimeinitialTime(7,Month::JUNE,2023,13,03,00,DayOfWeek::WEDNESDAY,SaveLight::SAVING_TIME_ACTIVE);RTC.setTime(initialTime);// Trigger the alarm every time the seconds are zero
RTCTimealarmTime;alarmTime.setSecond(0);// Make sure to only match on the seconds in this example - not on any other parts of the date/time
AlarmMatchmatchTime;matchTime.addMatchSecond();//sets the alarm callback
RTC.setAlarmCallback(alarmCallback,alarmTime,matchTime);}voidloop(){// in the loop, we continuously print the alarm's current state
// this is for debugging only and has no effect on the alarm whatsoever
unsignedlongcurrentMillis=millis();if(currentMillis-previousMillis>=interval){// save the last time you blinked the LED
previousMillis=currentMillis;Serial.print("Alarm state: ");Serial.println(ledState);}}// this function activates every minute
// and changes the ledState boolean
voidalarmCallback(){if(!ledState){digitalWrite(LED_BUILTIN,HIGH);}else{digitalWrite(LED_BUILTIN,LOW);}ledState=!ledState;}
/**
* RTC_NTPSync
*
* This example shows how to set the RTC (Real Time Clock) on the Portenta C33 / UNO R4 WiFi
* to the current date and time retrieved from an NTP server on the Internet (pool.ntp.org).
* Then the current time from the RTC is printed to the Serial port.
*
* Instructions:
* 1. Download the NTPClient library (https://github.com/arduino-libraries/NTPClient) through the Library Manager
* 2. Change the WiFi credentials in the arduino_secrets.h file to match your WiFi network.
* 3. Upload this sketch to Portenta C33 / UNO R4 WiFi.
* 4. Open the Serial Monitor.
*
* Initial author: Sebastian Romero @sebromero
*
* Find the full UNO R4 WiFi RTC documentation here:
* https://docs.arduino.cc/tutorials/uno-r4-wifi/rtc
*/// Include the RTC library
#include"RTC.h"//Include the NTP library
#include<NTPClient.h>#if defined(ARDUINO_PORTENTA_C33)
#include<WiFiC3.h>#elif defined(ARDUINO_UNOWIFIR4)
#include<WiFiS3.h>#endif
#include<WiFiUdp.h>#include"arduino_secrets.h" ///////please enter your sensitive data in the Secret tab/arduino_secrets.h
charssid[]=SECRET_SSID;// your network SSID (name)
charpass[]=SECRET_PASS;// your network password (use for WPA, or use as key for WEP)
intwifiStatus=WL_IDLE_STATUS;WiFiUDPUdp;// A UDP instance to let us send and receive packets over UDP
NTPClienttimeClient(Udp);voidprintWifiStatus(){// print the SSID of the network you're attached to:
Serial.print("SSID: ");Serial.println(WiFi.SSID());// print your board's IP address:
IPAddressip=WiFi.localIP();Serial.print("IP Address: ");Serial.println(ip);// print the received signal strength:
longrssi=WiFi.RSSI();Serial.print("signal strength (RSSI):");Serial.print(rssi);Serial.println(" dBm");}voidconnectToWiFi(){// check for the WiFi module:
if(WiFi.status()==WL_NO_MODULE){Serial.println("Communication with WiFi module failed!");// don't continue
while(true);}Stringfv=WiFi.firmwareVersion();if(fv<WIFI_FIRMWARE_LATEST_VERSION){Serial.println("Please upgrade the firmware");}// attempt to connect to WiFi network:
while(wifiStatus!=WL_CONNECTED){Serial.print("Attempting to connect to SSID: ");Serial.println(ssid);// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
wifiStatus=WiFi.begin(ssid,pass);// wait 10 seconds for connection:
delay(10000);}Serial.println("Connected to WiFi");printWifiStatus();}voidsetup(){Serial.begin(9600);while(!Serial);connectToWiFi();RTC.begin();Serial.println("\nStarting connection to server...");timeClient.begin();timeClient.update();// Get the current date and time from an NTP server and convert
// it to UTC +2 by passing the time zone offset in hours.
// You may change the time zone offset to your local one.
autotimeZoneOffsetHours=2;autounixTime=timeClient.getEpochTime()+(timeZoneOffsetHours*3600);Serial.print("Unix time = ");Serial.println(unixTime);RTCTimetimeToSet=RTCTime(unixTime);RTC.setTime(timeToSet);// Retrieve the date and time from the RTC and print them
RTCTimecurrentTime;RTC.getTime(currentTime);Serial.println("The RTC was just set to: "+String(currentTime));}voidloop(){}