Hello
I am making a master clock that drives a slave clock by sending a 500ms pulse with alternating polarity each minute.
I wrote a code to test my L298N H-Bridge and it is as follows
// connect motor controller pins to Arduino digital pins
// motor one
int enA = 10;
int in1 = 9;
int in2 = 8;
void setup()
{
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
}
void demoOne()
{
digitalWrite(enA, HIGH);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
delay(500);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
delay(60000);
// now switch polarity
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
delay(500);
// now turn off pulse
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
delay(60000);
}
void loop()
{
demoOne();
}
okay!
so now i have a Grove RTC (DS1307?)
and I would like to sync this code up with the RTC. Here is where I dont know enough about the arduino or the RTC.
EDIT: Using this code, now syncs with RTC, still trying to get action to happen at each 00 second (like a real clock) and best way to do a polarity reverse loop (each minute switch polarity) like in the above code
#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); // timer for every 15 seconds
//Alarm.timerOnce(10, OnceOnly); // called once after 10 seconds
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
digitalClockDisplay();
Serial.println("Ending setup....");
}
void loop(){
digitalClockDisplay();
Alarm.delay(1000);
}
void Repeats(){
Serial.println("PULSE");
digitalWrite(enA, HIGH);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
delay(500);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}
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);
}
i am interested in finding the most ELEGANT solution
![]()