Exposing rtc.now()

25 views
Skip to first unread message

Matias Andina

unread,
Dec 1, 2022, 4:14:21 PM12/1/22
to FEDforum
Hello all,
I was wondering how to expose the datetime from the RTC clock from FED into the .ino sketch.
Using the rtc declaration errors due to declaring rtc twice (once inside fed and twice inside the .ino). It would also be amazing to have a fed3.now() that just calls rtc.now(), but I don't want to modify the library before asking.
I'm using a bit of an older library (1.11) so this might have been included later on.
Best,
Matias

Lex

unread,
Dec 1, 2022, 4:29:23 PM12/1/22
to Matias Andina, FEDforum
Hey Matias!  A few months ago I tried figuring this same thing out but I could not do it, so instead I had the FED3 library store the contents of the DateTime object in individual variables that could be accessed from the .ino sketch.  In the latest library (v.1.16.3) you can use:
fed3.currentHour = now.hour()
fed3.currentMinute = now.minute()
fed3.currentSecond = now.second()
 fed3.unixtime = now.unixtime()

Does that accomplish what you need?  -Lex

--
You received this message because you are subscribed to the Google Groups "FEDforum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fedforum+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fedforum/CAAAsrMPX7D%3DaARWT9ebRWGs2%2BzwMyrz1J2Kiq9Te%2BXZpwp4ZUQ%40mail.gmail.com.

Matias Andina

unread,
Dec 1, 2022, 4:45:16 PM12/1/22
to Lex, FEDforum
Hi,
Initially, I was trying to implement it using .currentHour .currentMinute, but I was trying to hack my way into a multiple day schedule and it would be tough to do with those.

I think having this in the .cpp

DateTime FED3::now(){
  DateTime now = rtc.now();
  return now;
}

and this in the public portion of the .h
DateTime now();

might work. 

One issue that I have with this is that (if this works) and you have to call fed3.now() inside setup(), it will not be available in loop() unless made global
Best,
matias


Lex

unread,
Dec 1, 2022, 4:53:30 PM12/1/22
to Matias Andina, FEDforum
Cool if you test it out in the library and it works let me know?  Could you use fed3.unixtime to control a multi-day schedule? 

Matias Andina

unread,
Dec 1, 2022, 4:56:13 PM12/1/22
to Lex, FEDforum
While we are at it, these modification compile, but not sure if it would actually run, will test and update.
More details in the repo below, which also has a diagram of the experimental design.
The idea is to switch from habituation into "experiment mode" that has 2 continuous days with events given by the time.
 

Best,
Matias
Reply all
Reply to author
Forward
0 new messages