Secondary Clock ''СТРЕЛА" made in USSR

![20210812_111659|666x500, 50%](upload://dV4vgavgTGuHT6


mlYTCKeH0BXCi.jpeg)
Hello! Found and laundered a Soviet watch. For their operation, it is necessary to apply pulses of different polarity 24V alternately once a minute. There is arduino uno, module l298d, real time clock ds1307.
Help with the program.
/ SECONDARY CLOCK ARROW
int IN1 = 8; // output for L293d
int IN2 = 9; // output for L293d
int button = 10; // output for the button
void setup()
{
pinMode (button, INPUT); // configure the port as an input
pinMode (IN1, OUTPUT); // configure the port as an output to l293d
pinMode (IN2, OUTPUT); // configure the port as an output to l293d
}
void loop ()
{
if (digitalRead (button) == HIGH) // if the button is pressed

{
// MINUTE HAND AS SECOND
digitalWrite (IN1, HIGH);
digitalWrite (IN2, LOW);
delay (150);
digitalWrite (IN1, LOW);
digitalWrite (IN2, LOW);
delay (850);
digitalWrite (IN1, LOW);
digitalWrite (IN2, HIGH);
delay (150);
digitalWrite (IN1, LOW);
digitalWrite (IN2, LOW);
delay (850);

}
// MINUTE HAND STROKE
// If the button is not pressed
else {
// Give a pulse for 1 millisecond
digitalWrite (IN1, HIGH);
digitalWrite (IN2, LOW);
delay (150);
// turn off for 59850 milliseconds
digitalWrite (IN1, LOW); //
digitalWrite (IN2, LOW);
delay (59850);
// CHANGE POLARITY
// Give a pulse for 1 millisecond
digitalWrite (IN1, LOW); //
digitalWrite (IN2, HIGH);
delay (150);
digitalWrite (IN1, LOW); //
digitalWrite (IN2, LOW);
delay (59850);

}
}
How to make ds1307 count down the minutes?

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Hello
Post a timing diagram.

/ SECONDARY CLOCK ARROW
int IN1 = 8; // output for L293d
int IN2 = 9; // output for L293d
int button = 10; // output for the button

setting void ()
{
pinMode (button, INPUT); // configure the port as an input
pinMode (IN1, OUTPUT); // configure the port as an output to l293d
pinMode (IN2, OUTPUT); // configure the port as an output to l293d
}
empty loop ()
{
if (digitalRead (button) == HIGH) // if the button is pressed

{
// MINUTE HAND AS SECOND
digitalWrite (IN1, HIGH);
digitalWrite (IN2, LOW);
delay (150);
digitalWrite (IN1, LOW);
digitalWrite (IN2, LOW);
delay (850);
digitalWrite (IN1, LOW);
digitalWrite (IN2, HIGH);
delay (150);
digitalWrite (IN1, LOW);
digitalWrite (IN2, LOW);
delay (850);

}
// MINUTE HAND STROKE
// If the button is not pressed
else {
// Give a pulse for 1 millisecond
digitalWrite (IN1, HIGH);
digitalWrite (IN2, LOW);
delay (150);
// turn off for 59850 milliseconds
digitalWrite (IN1, LOW); //
digitalWrite (IN2, LOW);
delay (59850);
// CHANGE POLARITY
// Give a pulse for 1 millisecond
digitalWrite (IN1, LOW); //
digitalWrite (IN2, HIGH);
delay (150);
digitalWrite (IN1, LOW); //
digitalWrite (IN2, LOW);
delay (59850);

}
}

Write and test a function that makes the clock move one tick every time you press a button.

Now call that function whenever the minutes register on the RTC is not what it was the last time you looked.

Look, new minute sends the pulse, save the current minute.

You can look as often as you want; the tick may be a few milliseconds early or late. When this bothers you, take a slightly more complicated approach. If it is ever a problem.

You don't need anything else from the RTC other than to ensure that it is running.

a7

Please follow the advice given in the link below when posting code . Use code tags when posting code here to make it easier to read and copy for examination

Thank you, the theory is clear to me. But I don't know how to implement this in the code. I'm new to this business. If you could show an example.

Here's a function that runs the clock. If you could try it:

To replace the use of millis() as the basis for timekeeping in the linked simulation, you'll need to google up (or hunt down) some simple example programs showing how easy it is to connect and use the RTC module you have, and do some experiments.

If you download the RTC library, it comes with examples you can choose from the IDE. Otherwise the internets are full of "how to" get going with RTCs.

HTH

a7

You need to find a DS1307 library. Look at the examples that come with it. Fill in the parts that set up the device and read the minute and second.

// SECONDARY CLOCK ARROW
#include <DS1307.h>

const byte IN1 = 8; // output for L293d
const byte IN2 = 9; // output for L293d
const byte button = 10; // Input for the button

DS1307 rtc;

void setup()
{
  rtc.begin();
  pinMode (button, INPUT); // configure the port as an input
  pinMode (IN1, OUTPUT); // configure the port as an output to l293d
  pinMode (IN2, OUTPUT); // configure the port as an output to l293d
}

void SendMinutePulse()
{
  static bool Polarity = false;

  // Toggle polarity every pulse
  Polarity = !Polarity;

  if (Polarity)
  {
    // Give a positive pulse for 150 millisecond
    digitalWrite (IN1, HIGH);
    digitalWrite (IN2, LOW);
    delay (150);
    digitalWrite (IN1, LOW); //
    digitalWrite (IN2, LOW);
  }
  else
  {
    // Give a negative pulse for 150 millisecond
    digitalWrite (IN1, LOW); //
    digitalWrite (IN2, HIGH);
    delay (150);
    digitalWrite (IN1, LOW); //
    digitalWrite (IN2, LOW);
  }
}

void loop()
{
  static int PrevousMinute = 0;

  int minute = TheFunctionInYourDS1307LibraryThatReturnsTheCurrentMinute();

  if (minute != PrevousMinute)
  {
    // Entered a new minute
    PrevousMinute = minute;
    SendMinutePulse();
  }

  // If the button is down, move forward one minute each second
  if (digitalRead(button) == HIGH) // if the button is pressed
  {
    static int PrevousSecond = 0;

    int second = TheFunctionInYourDS1307LibraryThatReturnsTheCurrentSecond();

    if (second != PrevousSecond)
    {
      // Entered a new second
      PrevousSecond = second;
      SendMinutePulse();
    }
  }
}

You really making extra sure about those output states, no problem. But you should add

to setup() after you set the pin modes.

a7

If it has to be driven at 24 volts and with alternating polarity, one option would be to use an H bridge motor drive chip such as the L293D. This can be interfaced to an Arduino.

He's all over it!

a7

1 Like

Oops. I should have read the OP more carefully.

Thank you very much, tomorrow I will try and write you the result

ALTO777,Thank you very much, tomorrow I will try and write you the result

If you can, get a DS3231 RTC as they are superior to the ds1307.

Hello, I installed the library and gives an error when compiling DS1307/DS1307.h at master · filipeflop/DS1307 · GitHub

Why did you not post your code and error messages in code tags to make them easier to deal with ?

Did you actually read How to get the best out of this forum that I linked to previously ?

Like I said in Reply #9:

I have no way of knowing which of the many DS1307 libraries you might have chosen.