Childs Neopixel Sunrise Alarm Clock

Its been years since i played with an Arduino (Arrival of children have slowed down projects :slight_smile: ) so thought i could get back in the game with a project for my children. a sun rise clock to show when its time to get up. I Found a project online that was perfect for my needs

The only diffrence was that i have a DS3231 RTC spare and not the DS1307 so i change out the library no problems there but i keep receiving a error that i cant get my brain around

C:\Users\Yeti\Documents\Arduino\ClockSunshine\ClockSunshine.ino: In function 'void setup()':

ClockSunshine:24: error: 'RTC' was not declared in this scope

   setSyncProvider(RTC.get);   

                   ^

exit status 1
'RTC' was not declared in this scope

how would i declare this in my code bellow, thank you again for any help that anyone can give

#include <Time.h>
#include <TimeLib.h>
#include <Wire.h>
#include <RtcDS3231.h>
#include <TimeAlarms.h>
#include <FastLED.h>

#define NUM_LEDS 16
#define DATA_PIN 2

CRGB leds[NUM_LEDS];
CRGB OffColour = CRGB(0, 1, 2);
CRGB OnColour = CRGB(16, 8, 0);;

void setup()  
{
  //Create a time struct with the alarm time
  tmElements_t tm;
  tm.Hour = 7;
  tm.Minute = 0;
  tm.Second = 0;
  
  // Get the time from the rtc
  setSyncProvider(RTC.get);   
   
  // Initialise the LEDs in the ring
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

  //Used to test by setting the time to now + 5 seconds
  RTC.read(tm);
  tm.Second += 5;
  
  //Create an alarm for the morning
  Alarm.alarmOnce(tm.Hour, tm.Minute, tm.Second, LightsOn);  
    
  //Create an alarm an hour later to turn the lights off again
  Alarm.alarmOnce(tm.Hour + 1, tm.Minute, tm.Second, LightsOff);  
  
  // Set the initial colour of the LED's
  LightsOff();
}

void loop()
{
  // Alarm.delay has to be called occasionally to make the alarms work
  Alarm.delay(500);
}

//Create a sunrise style effect
void LightsOn()
{
  for(int i = 0; i < NUM_LEDS / 2; i += 1)
  {  
    leds[i] = OnColour;
    leds[NUM_LEDS - i - 1] = OnColour;

    FastLED.show();
    Alarm.delay(500);
  }
}

//Set the LED's all to the off colour
void LightsOff()
{
  for(int i = 0; i < NUM_LEDS; i += 1)
    leds[i] = CRGB(0, 1, 2);

  FastLED.show();
}

ClockSunshine.ino (1.37 KB)

You are trying to call a method on an instance you have not created.

Where do you do anything with the RtcDS3231 class?

Thanks will take another stab at it, I was using thr ds3231 a few years back for a pocket watch project and had 3 spare not being used. What is the best library to use with the Ds3231?

Where did you download the DS3231 library you’re using? I’m guessing that there’s nothing wrong with it. The trouble is, it’s DIFFERENT than the DS1307 library. Even though they probably have similar capabilities, they have different methods and are used differently.

You are using code that was developed specifically for the DS1307 library. So, you have two choices:

  1. Convert the code from the “Instructable” to use the DS3231 library.

  2. Switch to DS1307 hardware and library.

There are a lot of libraries out there with the same name but have different functions within them. However, the good news is that the 1307 and the 3231 are (almost) the same internally - close enough to be able to use the 1307 library with the 3231. So I would suggest getting the library used in the instructions, you should be ok.

To be pedantic the 1307 has a Clock Halt flag which tells you if the clock is running or not. The 3231 doesn't have this flag.

But, on top of that, as PaulS said:

You are trying to call a method on an instance you have not created.

Don’t know how different the hardware is, but the libraries are definitely different. The DS3231 library has a get() method (although OP is calling it with the wrong syntax), DS1307 library does not. If you look at the source code, you’ll see that DS1307RTC.cpp instantiates an object of type DS1307RTC (called RTC) for you. So that’s why OP’s code doesn’t do it. The DS3231 library doesn’t do this -- at least the one I found.