Timing question

Hello, I was looking codes of a project (k3ng antenna rotator) and, There was an option that I want to have…
Instead of asking the writer for a favor…it might be better to help the community…

There is a moon tracking module in the software, updating the antenna rotator headings according to the position of the moon with the intervals defined in MOON_TRACKING_CHECK_INTERVAL variable in the settings…

But what I need is to run this procedure every last 10 seconds of a minute instead of a continuous interval…

So if the seconds of the minute is 45- 46 47 48 49 it does nothing, but if it is 50-51 52 up to 59 … it may be running the moon track function as it needs to do…
A gps module is connected to the arduino for realtime date/time control…
Any help will be appreciated for sure…

Here is the sketch of this part…There should be another if at start to keep control of the timing I mentioned I guess.


if ((moon_tracking_active) && ((millis() - last_check) > MOON_TRACKING_CHECK_INTERVAL)) {

   update_time();
   update_moon_position();

   

   if ((moon_azimuth >= MOON_AOS_AZIMUTH_MIN) && (moon_azimuth <= MOON_AOS_AZIMUTH_MAX) && (moon_elevation >= MOON_AOS_ELEVATION_MIN) && (moon_elevation <= MOON_AOS_ELEVATION_MAX)) {
     submit_request(AZ, REQUEST_AZIMUTH, moon_azimuth * HEADING_MULTIPLIER, 11);
     submit_request(EL, REQUEST_ELEVATION, moon_elevation * HEADING_MULTIPLIER, 12);
     if (!moon_visible) {
       moon_visible = 1;
       #ifdef DEBUG_MOON_TRACKING
       debug.println("service_moon_tracking: moon AOS");
       #endif // DEBUG_MOON_TRACKING
     }
   } else {
     if (moon_visible) {
       moon_visible = 0;
         #ifdef DEBUG_MOON_TRACKING
       debug.println("service_moon_tracking: moon loss of AOS");
         #endif // DEBUG_MOON_TRACKING
     } else {
           #ifdef DEBUG_MOON_TRACKING
       debug.println("service_moon_tracking: moon out of AOS limits");
           #endif // DEBUG_MOON_TRACKING
     }
   }

   last_check = millis();
 }

Do you have a RTC connected? Or another means to get the actual tine of the day?

See, that's the problem with snippets; we have no idea what you're using and how it all fits together.

An update…
while digging on the internet i found the function tinygps (not tinygps++) has some functions that I can get the seconds from it…
Project uses tinygps instead of ++ version so I wanted to stick with it.

I changed the code as follows…

#ifdef FEATURE_MOON_TRACKING
void service_moon_tracking(){

//added for tinygpstime
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long fix_age;

 gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
//added for tinygpstime


  static unsigned long last_check = 0;
  static byte moon_tracking_activated_by_activate_line = 0;

  static byte moon_tracking_pin_state = 0;

  if (moon_tracking_active_pin) {
    if ((moon_tracking_active) && (!moon_tracking_pin_state)) {
      digitalWriteEnhanced(moon_tracking_active_pin, HIGH);
      moon_tracking_pin_state = 1;
    }
    if ((!moon_tracking_active) && (moon_tracking_pin_state)) {
      digitalWriteEnhanced(moon_tracking_active_pin, LOW);
      moon_tracking_pin_state = 0;
    }
  }

  if (moon_tracking_activate_line) {
    if ((!moon_tracking_active) && (!digitalReadEnhanced(moon_tracking_activate_line))) {
      moon_tracking_active = 1;
      moon_tracking_activated_by_activate_line = 1;
    }
    if ((moon_tracking_active) && (digitalReadEnhanced(moon_tracking_activate_line)) && (moon_tracking_activated_by_activate_line)) {
      moon_tracking_active = 0;
      moon_tracking_activated_by_activate_line = 0;
    }
  }

//added for tinygpstime

 if (second() >50 ) {
  if ((moon_tracking_active) && ((millis() - last_check) > MOON_TRACKING_CHECK_INTERVAL)) {

    update_time();
    update_moon_position();

    #ifdef DEBUG_MOON_TRACKING
    debug.print(F("service_moon_tracking: AZ: "));
    debug.print(moon_azimuth);
    debug.print(" EL: ");
    debug.print(moon_elevation);
    debug.print(" lat: ");
    debug.print(latitude);
    debug.print(" long: ");
    debug.println(longitude);
    #endif // DEBUG_MOON_TRACKING

    if ((moon_azimuth >= MOON_AOS_AZIMUTH_MIN) && (moon_azimuth <= MOON_AOS_AZIMUTH_MAX) && (moon_elevation >= MOON_AOS_ELEVATION_MIN) && (moon_elevation <= MOON_AOS_ELEVATION_MAX)) {
      submit_request(AZ, REQUEST_AZIMUTH, moon_azimuth * HEADING_MULTIPLIER, 11);
      submit_request(EL, REQUEST_ELEVATION, moon_elevation * HEADING_MULTIPLIER, 12);
      if (!moon_visible) {
        moon_visible = 1;
        #ifdef DEBUG_MOON_TRACKING
        debug.println("service_moon_tracking: moon AOS");
        #endif // DEBUG_MOON_TRACKING
      }
    } else {
      if (moon_visible) {
        moon_visible = 0;
          #ifdef DEBUG_MOON_TRACKING
        debug.println("service_moon_tracking: moon loss of AOS");
          #endif // DEBUG_MOON_TRACKING
      } else {
            #ifdef DEBUG_MOON_TRACKING
        debug.println("service_moon_tracking: moon out of AOS limits");
            #endif // DEBUG_MOON_TRACKING
      }
    }

    last_check = millis();
  }
}
[\code]

And later I had the error msg

:\Users\oguzhan\Desktop\k3ng_enson surum\k3ng_rotator_controller-master\k3ng_rotator_controller\k3ng_rotator_controller.ino:13835:10: warning: address of local variable ‘returnstring’ returned [-Wreturn-local-addr]

char returnstring[128] = “”;

^

exit status 1
‘second’ cannot be used as a function

sterretje:
Do you have a RTC connected? Or another means to get the actual tine of the day?

See, that’s the problem with snippets; we have no idea what you’re using and how it all fits together.

No RTC …just GPS and getting time info from GPS

You have a variable called second which is clashing with the second function. Call the variable something else.

if ((moon_tracking_active) && ((millis() - last_check) > MOON_TRACKING_CHECK_INTERVAL)) {
  if ((moon_tracking_active) &&
      ((millis() - last_check) >= 1000) &&
      currentSeconds >= 50 &&
      currentSeconds <= 59)
  {

Found my problem
added

 #ifdef FEATURE_MOON_TRACKING
void service_moon_tracking(){
//added for tinygpstime
int year;
byte month, day, hour, minute, gpssec, hundredths;
unsigned long fix_age;

 gps.crack_datetime(&year,&month,&day,&hour,&minute,&gpssec,&hundredths);
//
//added for tinygpstime

to the begining of the function

then
changed

if ((moon_azimuth >= MOON_AOS_AZIMUTH_MIN) && (moon_azimuth <= MOON_AOS_AZIMUTH_MAX) && (moon_elevation >= MOON_AOS_ELEVATION_MIN) && (gpssec >= 50) && (moon_elevation <= MOON_AOS_ELEVATION_MAX)) {
      submit_request(AZ, REQUEST_AZIMUTH, moon_azimuth * HEADING_MULTIPLIER, 11);
      submit_request(EL, REQUEST_ELEVATION, moon_elevation * HEADING_MULTIPLIER, 12);

added (gpssec >= 50)