Timealarms, Alarm not going off

Hey all,

I’m trying to make a wakeuplight like alarmclock, but I’m pretty lost. Most of my code works as intended but I’ve got a problem with the alarm. It doesn’t fire. I’ve changed all the delay()'s to alarm.delay(). It worked after I did that, so I started adding the rest of my code. Now it stopped working.

I also added Alarm.delay(5) to setup but no go.

Here’s the code (maybe a bit long)

Thanks in advance.

// []-------------------------
#include <Wire.h>
#include <RTClib.h>
#include <Bounce2.h>
#include <Time.h>
#include <TimeAlarms.h>
RTC_DS1307 RTC;
// ------------------------------------------


// [] ----------------------

int alarmHour = 19; // Fade in  (+/- 30 min)
int alarmMin = 48;


// []-----------------------------------------

#define BUTTON 2
#define WHITEPIN 12
#define LED 29
#define POTMETER A0


Bounce debouncer = Bounce(); 
int buttonState; 
unsigned long buttonPressTimeStamp;


int alarmSet = 1;
int potmeterValue = 0; 
int settingPotValue = 0;
int butPress = 0;
int ochtendFade = 0;
int currentW = 0;
int maxW = 255;
int fadeTime = 7000;
int ledState = 0;
unsigned long lastMillisOne = 0 ; 
unsigned long lastMillisTwo = 0 ; 
int sensorValue = 0;        // value read from the pot




void setup () {
   
    Serial.begin(9600);
    Wire.begin();
    RTC.begin();
    setSyncProvider(syncProvider);     //reference our syncProvider function instead of  RTC_DS1307::get()
    
    // following line sets the RTC to the date & time this sketch was compiled
    // RTC.adjust(DateTime(__DATE__, __TIME__));
  
    pinMode(BUTTON, INPUT);
    digitalWrite(BUTTON, HIGH);
    pinMode(WHITEPIN, OUTPUT);
     if (! RTC.isrunning()) { Serial.println("RTC is NOT running!"); }
    debouncer.attach(BUTTON);
    debouncer.interval(5);   
    setLed(1);   
    Alarm.alarmRepeat(alarmHour,alarmMin,0, alarmOn);
    testAllLights();
    Alarm.delay(5);
}

void loop () {


 getPotValue();
 ochtendFadeIn(); 
 readButtonState();
  digitalClockDisplay();
}


void digitalClockDisplay(){
  // digital clock display of the time
  if ( millis() - lastMillisTwo >= 5000 ) {
  lastMillisTwo = millis();
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
  }
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}



void alarmOn () { 
  Serial.println("Alarm time!");
  if(alarmSet == 1) {
    digitalClockDisplay();
    Serial.println("Alarm on!");
    ochtendFade = 1;
  }
}

void ochtendFadeIn () {
  if(ochtendFade == 1){
    Serial.println("Alarm running!");
    if(millis() - lastMillisOne > fadeTime){
      lastMillisOne = millis();
      if(currentW < 255){
        currentW++;
        analogWrite(WHITEPIN, currentW);
      }
      Serial.println("---");
      digitalClockDisplay();
       Serial.print("Set brightness: ");
       Serial.println(currentW);
    if(currentW > maxW) { ochtendFade = 2; }
    }
  }
}
    
void ochtendLichtUit () { 
  Serial.println("Alarm off!");
  ochtendFade = 0;
  for (currentW = currentW; currentW > -1; currentW--) {
    analogWrite(WHITEPIN, currentW);
    Alarm.delay(4);
 }
}




void readButtonState () {
  boolean changed = debouncer.update();
  if ( changed ) {
       // Get the update value
     int value = debouncer.read();
    if ( value == HIGH ) {
        buttonState = 0;
        Serial.println("Button (state 0)");
       //Button released (state 0)
    } 
    else {
      Serial.println("Button (state 1)");
      buttonPressTimeStamp = millis();
      if ( settingPotValue > 0 ) { 
        stopSetPotValue();
        setLed(alarmSet);
      }
      else {
        if (ochtendFade > 0) { 
          ochtendLichtUit();
        }
        else{  
        buttonState = 1;
        switchAlarm();
        }
      }
    }
  }
   if  ( buttonState == 1 ) {
   Serial.print("Buttontimer: ");
   Serial.println(millis() - buttonPressTimeStamp);
    if ( millis() - buttonPressTimeStamp >= 2000 ) {
        switchAlarm();
        startSetPotValue();
        buttonState = 2;
        Serial.println("Button (state 2)");
       //Button held for two seconds (state 2)
    }
  }
}



void switchAlarm () {
  Serial.print("Switchalarm! Alarmset: ");
  Serial.print(alarmSet);
  Serial.print("  Alarm is now: ");
 
  if ( alarmSet == 1 ) { 
  alarmSet = 0; 
  setLed(0);
  Serial.println("off");
  }
  else { 
  alarmSet = 1; 
  setLed(1);
  Serial.println("on");
  }

}

void startSetPotValue () {
  for (currentW = 0; currentW < maxW; currentW++) {
    analogWrite(WHITEPIN, currentW);
    Alarm.delay(4);
  }
  settingPotValue = 2;
}
void stopSetPotValue () {
    fadeTime = 1800000 /  maxW;
    Serial.print("Set Pot Value! Fadetime: ");
    Serial.print(fadeTime);
    Serial.println("ms");
    for (currentW = maxW; currentW > -1; currentW--) {
    analogWrite(WHITEPIN, currentW);
    Alarm.delay(4);
   }
  settingPotValue = 0;
}

void getPotValue () {
  if ( settingPotValue == 2 ) {
  sensorValue = analogRead(POTMETER); 
  maxW = map(sensorValue, 0, 1023, 0, 255);
  if(maxW < 50) { maxW = 50; }
  if(maxW > 240) { maxW = 255; } 
  currentW = maxW;
  analogWrite(WHITEPIN, currentW);
 // Serial.print("sensor = " );                       
 // Serial.print(sensorValue);      
 // Serial.print("\t Max Brightness: ");      
 // Serial.println(maxW);   
  Alarm.delay(2);
  }
}

void setLed(byte ledSet) {
  if ( ledSet == 1 ) { digitalWrite(LED, HIGH); }
  if ( ledSet == 0 ) { digitalWrite(LED, LOW); }
}


void testAllLights () {
// fade in white
  for (currentW = 0; currentW < 256; currentW++) {
    analogWrite(WHITEPIN, currentW);
    Alarm.delay(4);
  }
// fade out white
  for (currentW = 255; currentW > -1; currentW--) {
    analogWrite(WHITEPIN, currentW);
    Alarm.delay(4);
   }

}



time_t syncProvider()     //this does the same thing as RTC_DS1307::get()
{
  return RTC.now().unixtime();
}

The way that the alarm knows that time has passed if because you call Alarm.delay(). It looks like you almost never call Alarm.delay(), so it might take a while for the alarm to go off.

Ah I figured once might be enough. I'll add some more.

Edit: That did the job! Thanks a bunch! :)