Substituting the sunrise result into a variable

I succeeded in getting the sunrise and sunset times through serial communication using the code below with Arduino Uno. But sadly I don’t know how to turn on the LED(D13 port) by substituting that value into a variable. Can you help me?

All I want to know is how to store the sunrise sunset value that the <TimeLord.h> library tells us in a variable.

#include <TimeLord.h>

// what is our longitude (west values negative) and latitude (south values negative)
float const LONGITUDE = 145.00;
float const LATITUDE = -37.00;

void setup ()
  {
    
  Serial.begin (115200);
  
  TimeLord tardis; 
  tardis.TimeZone(10 * 60); // tell TimeLord what timezone your RTC is synchronized to. You can ignore DST
  // as long as the RTC never changes back and forth between DST and non-DST
  tardis.Position(LATITUDE, LONGITUDE); // tell TimeLord where in the world we are
  
  byte today[] = {  0, 0, 12, 27, 10, 2012    }; // store today's date (at noon) in an array for TimeLord to use

if (tardis.SunRise(today)) // if the sun will rise today (it might not, in the [ant]arctic)
   {
   Serial.print("Sunrise: ");
   Serial.print((int) today[tl_hour]);
   Serial.print(":");
   Serial.println((int) today[tl_minute]);
   }
   
   if (tardis.SunSet(today)) // if the sun will set today (it might not, in the [ant]arctic)
   {
   Serial.print("Sunset: ");
   Serial.print((int) today[tl_hour]);
   Serial.print(":");
   Serial.println((int) today[tl_minute]);
   }
   Serial.println(); 
  }
  
void loop () {}

I’m not sure what you’re asking - what LED?

And when should the LED you don’t have yet be on and off?

You also have no RTC, so no way to know what time it is…

a7

If you can turn on the LEDs in time for sunrise and sunset, you can turn on a light bulb and turn on a relay, so any LED is not a problem. (Even the D13 port)

I want the LED to turn on at sunset, and to turn off the LED at sunrise. The example of turning on the D13 port doesn’t matter.

RCT is using ds1302. All other issues have been resolved. I just want to know how to put the result of sunrise and sunset into a variable.

OK, I just googled

“ arduino compare rtc to a time “

no quotes, and there are many kinks links that look like they might help you compare times that the TimeLord tells you about to the time you get by using an RTC.

Which (“RTC arduino”) might google up another bunch of plausible leads.

That’s the beauty of google and Arduino. It is unlikely at the beginning that you will be inventing any wheels - look around the internet and some clown somewhere will have chewed your cabbage already.

a7

Thank you.
Looks like I’m asking the wrong question. All I want to know is how to store the sunrise sunset value that the <TimeLord.h> library tells us in a variable.

Read the TimeLoad documentation.

It looks like after you call tardus.SunRise you will have

hours are in the array you passed and can be used like

byte myHour = today[tl_hour];

and similarly minutes can be used like

byte myMinute = today[tl_minute];

if you really want to have it that way, but there’s actually no need to do - the values are in the array you passed to the TimeLord, so just use them.

Do you know how arrays and using them as arguments to functions work?

Nice library, in any event. Yhanks for drawing attention to it.

a7

1 Like

Thank you. I will try using the variable you provided. If I hadn’t been a beginner, I wouldn’t have had to ask these basic questions.
Good luck to you.

Well, thank you, but I’ve run out of luck long ago and base my hopes for success on other things that seem, for me, to be more important.

Good day to you, sir! :wink:

a7

Wouldn’t it be rude to ask how to combine those two variables into one?

It wouldn’t.

How do you want to combine hours and minutes into one variable?

I’ll guess since you a bit vague.

int minutesSinceMidnight = hours * 60 + minutes;

But srsly, seems like you are afraid to learn about arrays. There may be no need to do what you are asking about. Besides, sooner later you are going to have to know about and exploit arrays, so why not start now?

HTH

a7

Thank you. I solved it with an array.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.