Kinetic Clock Project Fails to Compile

I found this very cool 7-segment clock at [https://www.instructables.com/Kinetic-Digital-Clock-Arduino-3D-Print/]
I am using the Arduino Mega2560 by ELEGOO, Keystudio Mega Sensor Shield, and the DS3231 Real Time Clock. All wiring has been inspected and is correct per project build instructions.
When I compile I cannot get past the RTC setup, Here is the error message
C:Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino:5:19: error: no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)'
DS3231 rtc(SDA,SCL);
^
In file included from C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino:3:0:
c:\Users\drew\OneDrive\Desktop\Arduino\libraries\DS3231/DS3231.h:73:3: note: candidate: DS3231::DS3231(TwoWire&)
DS3231(TwoWire & w);
^~~~~~
c:\Users\drew\OneDrive\Desktop\Arduino\libraries\DS3231/DS3231.h:73:3: note: candidate expects 1 argument, 2 provided
c:\Users\drew\OneDrive\Desktop\Arduino\libraries\DS3231/DS3231.h:72:3: note: candidate: DS3231::DS3231()
DS3231();
^~~~~~
c:\Users\drew\OneDrive\Desktop\Arduino\libraries\DS3231/DS3231.h:72:3: note: candidate expects 0 arguments, 2 provided
c:\Users\drew\OneDrive\Desktop\Arduino\libraries\DS3231/DS3231.h:68:7: note: candidate: constexpr DS3231::DS3231(const DS3231&)
class DS3231 {
^~~~~~
c:\Users\drew\OneDrive\Desktop\Arduino\libraries\DS3231/DS3231.h:68:7: note: candidate expects 1 argument, 2 provided
c:\Users\drew\OneDrive\Desktop\Arduino\libraries\DS3231/DS3231.h:68:7: note: candidate: constexpr DS3231::DS3231(DS3231&&)
c:\Users\drew\OneDrive\Desktop\Arduino\libraries\DS3231/DS3231.h:68:7: note: candidate expects 1 argument, 2 provided
C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino: In function 'void setup()':
C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino:82:5: error: 'class DS3231' has no member named 'begin'
rtc.begin();
^~~~~
C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino: At global scope:
C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino:118:24: error: 'class DS3231' has no member named 'getTimeStr'; did you mean 'getMinute'?
String timeStr = rtc.getTimeStr()
^~~~~~~~~~
getMinute
C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino:121:3: error: expected unqualified-id before 'for'
for (int activeDigit = 0; activeDigit < 4; activeDigit++) {
^~~
C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino:121:29: error: 'activeDigit' does not name a type; did you mean 'isDigit'?
for (int activeDigit = 0; activeDigit < 4; activeDigit++) {
^~~~~~~~~~~
isDigit
C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino:121:46: error: 'activeDigit' does not name a type; did you mean 'isDigit'?
for (int activeDigit = 0; activeDigit < 4; activeDigit++) {
^~~~~~~~~~~
isDigit
C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino:155:8: error: expected constructor, destructor, or type conversion before '(' token
delay(STEP_MS);
^
C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino:156:3: error: 'timeMS' does not name a type
timeMS = timeMS + STEP_MS;
^~~~~~
C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino:159:3: error: expected unqualified-id before 'if'
if (timeMS >= COUNT_MS) {
^~
C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino:164:3: error: expected unqualified-id before 'for'
for (int i = 0; i < DIGITS; i++) {
^~~
C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino:164:19: error: 'i' does not name a type
for (int i = 0; i < DIGITS; i++) {
^
C:\Users\drew\OneDrive\Desktop\Arduino_KeniticClock_copy_20240912105013_KeniticClock_copy_20240912105013.ino:164:31: error: 'i' does not name a type
for (int i = 0; i < DIGITS; i++) {
^

exit status 1

Compilation error: no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)'

And here is the entire .ino


```cpp
String input;
#include <Servo.h>
#include <DS3231.h>

DS3231 rtc(SDA, SCL);

const int DIGIT_TO_SEGMENT_MAPPING[10][7] = {
  { 1, 1, 1, 1, 1, 1, 0 },  // 0
  { 0, 1, 1, 0, 0, 0, 0 },  // 1
  { 1, 1, 0, 1, 1, 0, 1 },  // 2
  { 1, 1, 1, 1, 0, 0, 1 },  // 3
  { 0, 1, 1, 0, 0, 1, 1 },  // 4
  { 1, 0, 1, 1, 0, 1, 1 },  // 5
  { 1, 0, 1, 1, 1, 1, 1 },  // 6
  { 1, 1, 1, 0, 0, 0, 0 },  // 7
  { 1, 1, 1, 1, 1, 1, 1 },  // 8
  { 1, 1, 1, 1, 0, 1, 1 },  // 9
};
const int SEGMENT_INTERVALS[4][7][2] = {
  { { 141, 54 },
    { 155, 69 },
    { 150, 73 },
    { 151, 70 },
    { 159, 75 },
    { 159, 75 },
    { 125, 40 } },
  { { 164, 76 },
    { 155, 76 },
    { 138, 61 },
    { 180, 87 },
    { 151, 63 },
    { 145, 57 },
    { 165, 78 } },
  { { 157, 73 },
    { 156, 70 },
    { 165, 85 },
    { 137, 52 },
    { 133, 50 },
    { 133, 50 },
    { 168, 73 } },
  { { 131, 52 },
    { 147, 61 },
    { 131, 51 },
    { 158, 69 },
    { 155, 73 },
    { 116, 28 },
    { 137, 60 } }
};
const int COLON_INTERVAL[2][2] = {
  { 141, 62 },
  { 137, 30 },
};
const int DIGIT_STARTING_SEGMENT_INDEX[4] = { 2, 9, 22, 29 };
const int COLON_STARTING_INDEX = 16;

const int START_POS = 0;
const int COLON = 2;
const int DIGITS = 4;
const int SEGMENTS_PER_DIGIT = 7;
const int STEP_MS = 20;
const int COUNT_MS = 2000;
const int NUM_SERVOS = DIGITS * SEGMENTS_PER_DIGIT;

int servoTargetDestination[DIGITS][NUM_SERVOS];
int servoTargetDestinationColon[COLON];

int count = 1200;
int timeMS = 0;

Servo servos[DIGITS][SEGMENTS_PER_DIGIT];
Servo colonServos[COLON];

void setup() {
  rtc.begin();
  for (int i = 0; i < DIGITS; i++) {
    for (int j = 0; j < SEGMENTS_PER_DIGIT; j++) {
      int offset = DIGIT_STARTING_SEGMENT_INDEX[i];
      servoTargetDestination[i][j] = SEGMENT_INTERVALS[i][j][START_POS];
      servos[i][j].attach(j + offset);
      servos[i][j].write(servoTargetDestination[i][j]);
    }
  }
  delay(500);
  for (int i = 0; i < DIGITS; i++) {

    for (int j = 0; j < SEGMENTS_PER_DIGIT; j++) {
      servos[i][j].detach();
    }
  }
  for (int i = 0; i < COLON; i++) {
    colonServos[i].attach(i + COLON_STARTING_INDEX);
    colonServos[i].write(COLON_INTERVAL[i][START_POS]);
  }
  delay(500);
  for (int i = 0; i < COLON; i++) {
    colonServos[i].detach();
  }
  for (int i = 0; i < COLON; i++) {
    colonServos[i].attach(i + COLON_STARTING_INDEX);
    colonServos[i].write(COLON_INTERVAL[i][1]);
  }
  delay(500);
  for (int i = 0; i < COLON; i++) {
    colonServos[i].detach();
  }
}
void loop() {}
// Retrieve and cleanup RTC string. "12:45" -> "1245"
String timeStr = rtc.getTimeStr()
                   String timeString = timeStr.substring(0, 2) + timeStr.substring(3, 5);

for (int activeDigit = 0; activeDigit < 4; activeDigit++) {

  // Step 1: Set servoTargetDestination
  String stringCount = String(count);  // Swap to timeString to use the clock
  // Remove String stringCount = String(timeString);
  for (int i = 0; i < SEGMENTS_PER_DIGIT; i++) {
    int displayNumber = stringCount.charAt(timeString.length() - 1 - activeDigit) - '0';
    int placement = (activeDigit == 3 && displayNumber == 0) ? 0 : DIGIT_TO_SEGMENT_MAPPING[displayNumber][i];
    servoTargetDestination[activeDigit][i] = SEGMENT_INTERVALS[activeDigit][i][placement];
  }

  // Step 2: Increment Segments
  for (int i = 0; i < SEGMENTS_PER_DIGIT; i++) {

    Servo servo = servos[activeDigit][i];
    int pos = servo.read();
    int dest = servoTargetDestination[activeDigit][i];
    if (pos != dest) {
      if (pos < dest) {
        pos++;
      } else {
        pos--;
      }
      if (!servo.attached()) {
        int offset = DIGIT_STARTING_SEGMENT_INDEX[activeDigit];
        servo.attach(i + offset);
      }
      servo.write(pos);
    }
  }
}
// Step 3: Wait
delay(STEP_MS);
timeMS = timeMS + STEP_MS;

// Step 4A: Countdown
if (timeMS >= COUNT_MS) {
  timeMS = 0;
  count = count + 1;
}
// Step 5: Detach anything that is at its destination
for (int i = 0; i < DIGITS; i++) {
  for (int j = 0; j < NUM_SERVOS; j++) {
    Servo servo = servos[i][j];
    int pos = servo.read();
    int destination = servoTargetDestination[i][j];
    if (pos == destination && servo.attached()) {
      servos[i][j].detach();
    }
  }
}

Libraries are installed and updated. Can someone help me resolve this problem.

The problem is the code to intialise the RTC:

DS3231 rtc(SDA, SCL);

Whereas all you need is:

DS3231 rtc;

You may also have a superfluous comma after the second set of parameters here:

const int COLON_INTERVAL[2][2] = {
  { 141, 62 },
  { 137, 30 },
}; 

Superfluous definitely, as in unnecessary. But also harmless... it is a case of the forgivable trailing comma. As such, it is not a syntax error.

google

C++ trailing comma

if this would otherwise keep you awake at night. :expressionless:

a7

All very comforting to know, but completely irrelevant if the code won't compile!

Please always post error messages inside code tags, because... it seems to go on forever! The code tags put it into a scrollable window.

(Don't put error messages inside the same pair of code tags as the code itself, they are different things after all.)

Thanks Bitseeker. I removed (SDA, SCL) and got a little further down the code. Here is the next error

C:\Users\drew\OneDrive\Desktop\Arduino\_KeniticClock_copy_20240912105013\_KeniticClock_copy_20240912105013.ino:74:7: error: 'class DS3231' has no member named 'begin'
   rtc.begin();
       ^~~~~
C:\Users\drew\OneDrive\Desktop\Arduino\_KeniticClock_copy_20240912105013\_KeniticClock_copy_20240912105013.ino: At global scope:
C:\Users\drew\OneDrive\Desktop\Arduino\_KeniticClock_copy_20240912105013\_KeniticClock_copy_20240912105013.ino:109:22: error: 'class DS3231' has no member named 'getTimeStr'; did you mean 'getMinute'?
 String timeStr = rtc.getTimeStr()
                      ^~~~~~~~~~
                      getMinute
C:\Users\drew\OneDrive\Desktop\Arduino\_KeniticClock_copy_20240912105013\_KeniticClock_copy_20240912105013.ino:112:1: error: expected unqualified-id before 'for'
 for (int activeDigit = 0; activeDigit < 4; activeDigit++) {
 ^~~
C:\Users\drew\OneDrive\Desktop\Arduino\_KeniticClock_copy_20240912105013\_KeniticClock_copy_20240912105013.ino:112:27: error: 'activeDigit' does not name a type; did you mean 'isDigit'?
 for (int activeDigit = 0; activeDigit < 4; activeDigit++) {
                           ^~~~~~~~~~~
                           isDigit
C:\Users\drew\OneDrive\Desktop\Arduino\_KeniticClock_copy_20240912105013\_KeniticClock_copy_20240912105013.ino:112:44: error: 'activeDigit' does not name a type; did you mean 'isDigit'?
 for (int activeDigit = 0; activeDigit < 4; activeDigit++) {
                                            ^~~~~~~~~~~
                                            isDigit
C:\Users\drew\OneDrive\Desktop\Arduino\_KeniticClock_copy_20240912105013\_KeniticClock_copy_20240912105013.ino:144:6: error: expected constructor, destructor, or type conversion before '(' token
 delay(STEP_MS);
      ^
C:\Users\drew\OneDrive\Desktop\Arduino\_KeniticClock_copy_20240912105013\_KeniticClock_copy_20240912105013.ino:145:1: error: 'timeMS' does not name a type
 timeMS = timeMS + STEP_MS;
 ^~~~~~
C:\Users\drew\OneDrive\Desktop\Arduino\_KeniticClock_copy_20240912105013\_KeniticClock_copy_20240912105013.ino:148:1: error: expected unqualified-id before 'if'
 if (timeMS >= COUNT_MS) {
 ^~
C:\Users\drew\OneDrive\Desktop\Arduino\_KeniticClock_copy_20240912105013\_KeniticClock_copy_20240912105013.ino:153:1: error: expected unqualified-id before 'for'
 for (int i = 0; i < DIGITS; i++) {
 ^~~
C:\Users\drew\OneDrive\Desktop\Arduino\_KeniticClock_copy_20240912105013\_KeniticClock_copy_20240912105013.ino:153:17: error: 'i' does not name a type
 for (int i = 0; i < DIGITS; i++) {
                 ^
C:\Users\drew\OneDrive\Desktop\Arduino\_KeniticClock_copy_20240912105013\_KeniticClock_copy_20240912105013.ino:153:29: error: 'i' does not name a type
 for (int i = 0; i < DIGITS; i++) {
                             ^

exit status 1

Compilation error: 'class DS3231' has no member named 'begin'````

Hi PaulRB. I thought I did put both the code and the error message in two separate code tags by using the as instructed. Where did I go wrong?

You didn't do that, I was just warning you about it. Sone new members really struggle with code tags and put code, error messages, their questions for the forum (which shouldn't be in code tags at all), everything, inside one set of code tags.

But you still haven't fixed your original post.

I suspect there is more than one DS3231 library around, by different authors, and you installed the wrong one for your code.

Did you install it from library manager? If so, which one exactly? If not, can you post a link to the one you installed?

The one you need may be this one

Yes, sorry I missed that and led you up the garden path a bit!. In the article it doesn't state where to download the library from or which one was used and I had assumed the standard Arduino one. However, there was a clue in the comments in one of the snippets that the library used was from Rinky Dink Electronics. A quick google finds this:

http://www.rinkydinkelectronics.com/library.php?id=73

which appears to be the same Hemming Karlesen library that PaulRB posted a link to.

Despite serving the same functions, libraries by different authors may not be code compatible with each other, having differing class and object definitions and hence a different format/naming for the calls used. Hence one library requires DR3231(SDA, SCL); another needs just DS3231 rtc; One may need rtc.begin(). Another doesn't and so on. Either the library used by the author of the example needs to be used for the code to compile correctly, or else the code needs to be re-written to match the library being used.

As PaulRB suggests, please post a link to the library that you installed. You probably need to remove that one and install the one he linked and restore the code to the original example.

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