run code one minute, toggle pins, run same code next minute. RTC

Hello

I have a topic on feasibility about this

but i thought programming questions might be more suited.

I am trying to make a master clock to drive a slave clock

with an H bridge, i send a 500ms pulse using two pins to define polarity. I wait one minute then i switch the state? (high low) of two pins to reverse polarity.

this is the code

int enA = 10;
int in1 = 9;
int in2 = 8;
void setup()
{
  // 
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
}
void demoOne()
{ // pulse one pin
  digitalWrite(enA, HIGH);
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  delay(500);
   digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);

   delay(60000);
  // now pulse second pin
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);  
 
  delay(500);
  // now turn off 
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW); 
   delay(60000); 
}

void loop()
{
  demoOne();
 
}

since it is a clock! i wanted to integrate an RTC.

here is my first problem : i dont know how to make the code run at every 00 second (every minute on the minute) or if this is even possible, if not possible i will just start the code at a corresponding time.

so i integrated an RTC code
and aarg proposed some changes that i havent been able to integrate

#include <DS1307RTC.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <Wire.h> 

int enA = 10;
int in1 = 9;
int in2 = 8; 


void setup()
{
  Serial.begin(9600);
  Serial.println("In setup....");
  /*
  using rtc, sync system time to rtc
   setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011 //old way *****************
   */

  // following lines added to set time from rtc, took from timeRtcSet example, added jim *****************
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if (timeStatus() != timeSet) 
    Serial.println("Unable to sync with the RTC");
  else
    Serial.println("RTC has set the system time");
  // end of setting the time ******************************


Alarm.timerRepeat(60, Repeats(int pinNumber));            // pulse every 60   seconds



  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  digitalClockDisplay();
  Serial.println("Ending setup....");
}




void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println(); 
}

void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void Repeats(int pinNumber){
 Serial.println("PULSE");
 digitalWrite(pinNumber, HIGH);
 delay(500);
 digitalWrite(pinNumber, LOW);
}


void  loop(){  
  digitalClockDisplay();
  Alarm.delay(1000);
  Repeats(in1);
  Repeats(in2);
  
}

i dont really know where to declare int pinNumber , nor where i should put Repeats(in1);
Repeats(in2);

if you have a more simple solution, or something more calibrated to my [limited] understanding it would be much appreciated.

sorry, total noob trying to cut and paste my way to understanding.

here is my first problem : i dont know how to make the code run at every 00 second (every minute on the minute) or if this is even possible, if not possible i will just start the code at a corresponding time.

On any given pass through loop(), the second value might be 0, or it might not. If it is, it might have been zero last time, or it might not. If it is now, and was not last time, it has just become 0, so start the process.

i dont really know where to declare int pinNumber , nor where i should put Repeats(in1);
Repeats(in2);

In the closet, with the crutches. With an RTC, you don't need the Alarm class.

cool

anybody else interested in proposing another solution? or perhaps translating PaulS 's poetry into workable code?

thanks everyone

Why is all this not in your other Thread where everyone can have access to all the information ?

Ask the moderator to merge this into the other Thread

...R

Suppose you have a variable called thisSecond that you populate from the RTC. Suppose that you have a variable called lastSecond that has an initial value of 0. Suppose that you set lastSecond to thisSecond as the last step in loop().

Now, suppose that on any pass through loop(), you do:

   thisSecond = getValueFromRTC();
   if(thisSecond == 0)
   {
      // The time IS right to do something, IF
      // we haven't already done it
      if(thisSecond != lastSecond)
      {
         // The time has just BECOME right,
         // so we need to do it
         doIt();
      }
   }

Would that work? (Rhetorical question; of course it will.)
Can you see how to implement it?