Not declared in scope?

Hey everyone,

I’m pretty new to Arduino. I’ve got a little bit of coding experience but none in C++. Just some Python and pretty good with Matlab, both self taught so my code might not exactly follow best practices (feel free to point out any of those issues too, I’m still learning as I go).

I was working on a library for a MCP7940M chip based on this one: Anarduino/Anarduino/avr/libraries/MCP7940RTC at master · sumotoy/Anarduino · GitHub
I made a couple of changes because a) it didn’t work as is and b) I needed some extra functionality.

For some reason when I run it I get the following error that’s gotten the best of me:

...MCP7940MRTC.cpp:155:34: error: 'dec2bcd' was not declared in this scope

  b[0] |= dec2bcd(tm.Second & 0x7f);  // stop the oscillator and write the data

The codes too long to post so I’ve attached the .h and .cpp below. If it’s easier I can post snippets.

Thanks in advance for any help, this one’s really got me.

MCP7940MRTC.cpp (16.5 KB)

MCP7940MRTC.h (1.67 KB)

Change line 128 of MCP7940MRTC.cpp from:

void setTimeRTC(int year, int month, int day, int day_of_week, int hour, int minute, int second) {


void MCP7940MRTC::setTimeRTC(int year, int month, int day, int day_of_week, int hour, int minute, int second) {

Oh wow, so it was just something stupid. Thanks for finding that pert. How were you able to do that so quickly?!

The error gives the file and line where the error occurs (MCP7940MRTC.cpp line 155) so I just downloaded the file and had a look in that general area. I've definitely had a good bit of experience spotting bugs over my years working on the Arduino project, as well as my own code. I've might have done something like this myself a couple times.

It's definitely helpful to have a general understanding of C++. Otherwise it would be easy to get stuck on thinking "The declaration is right there in the .h file, so why the heck am I getting this error?". You will rarely see classes implemented in Arduino sketches but they're used in practically every Arduino library. Once you dive into libraries it's worth studying up on them and writing some simplified test programs to make sure you got it.

Ya, working my way up to self sufficiency - thanks for lending your experienced eyes, probably would've spent a few more hours on it before giving up, then looking again a few days from from now and finally having it pop up at me (or not...)