Control 4 Stepper Motors from RTC

Hi all,

I've seen a linear clock online (here) I've decided to have a go at building. I'm fairly new to Arduino and I've never tried anything this complex.

component list so far:

1x Arduino mega
4 x 28byj-48 with ULN2003AN driver
1x RTC DS1307
1x 5v LED strip for backlighting
1x 5v power supply - 2A

I've got as far as using AccelStepper to drive the motors for one revolution back and forward etc using the code they provided. I don't understand how to get time from the RTC and convert it to a number of steps for the stepper motors I have to drive it to the correct position.

There person who originally made the clock has uploaded his code online and I have included it below but I'm afraid its above my current level of knowledge to understand how they have gone from the RTC to the stepper motors .

I'd appreciate if someone could point me to a resource to understand how this works or explain it to me.

#include <Stepper.h>
#include "RTClib.h"

#define STEPPER_ON 14

RTC_DS3231 rtc;

class ClockDigit {
  // Digits are zero to (num_digits - 1) [inclusive]
  int8_t current_digit = 0; // All digits should start at zero
  int8_t invert_direction = 1;

  static const int STEPS_PER_REVOLUTION = 2038;
  static const int STEPS_PER_DIGIT = 560;

  Stepper stepper;
  
public:
  ClockDigit(int8_t dir, int blu, int yel, int pnk, int ora) 
    : invert_direction(dir), stepper(Stepper(STEPS_PER_REVOLUTION, blu, yel, pnk, ora)) {
      stepper.setSpeed(15);
  }

  void set_to_digit(uint8_t digit) {
    int delta_digits = digit - current_digit;
    stepper.step(invert_direction * STEPS_PER_DIGIT * delta_digits);
    
    current_digit = digit;
  }
};

ClockDigit hour_ms(1, 16,15,17,5);
ClockDigit hour_ls(-1, 3,15,2,5);
ClockDigit minute_ms(1, 8,6,7,4);
ClockDigit minute_ls(-1, 12,9,11,10);

void setup() {
  pinMode(STEPPER_ON, OUTPUT);
  
//  Serial.begin(57600);
  delay(1000);

  // Stop execution if the RTC clock is not present
  if (!rtc.begin()) {
    abort();
  }

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