ESP8266 With speaker and rtc module to make chime

i am trying to play a chime note that i have saved in hex format in code and wanted to play it on starting of every hour. but it plays 2 seconds and stops without completion of it. am using a tip122 npn darlington transistor in speaker output. when i check it via uploading code only to play it it works, but when i interface it with ds1307 rtc the code not works. can any body give me a solution of the problem...

#include <Arduino.h>
#include <Wire.h>
#include <RTClib.h>
#include "AudioFileSourcePROGMEM.h"
#include "AudioGeneratorWAV.h"
#include "AudioOutputI2SNoDAC.h"

RTC_DS1307 RTC;

// Define the chime audio file
#include "chime.h"

AudioGeneratorWAV *wav;
AudioFileSourcePROGMEM *file;
AudioOutputI2SNoDAC *out;

void playChime() {
  audioLogger = &Serial;
  file = new AudioFileSourcePROGMEM(chime, sizeof(chime));
  out = new AudioOutputI2SNoDAC();
  wav = new AudioGeneratorWAV();
  wav->begin(file, out);

  while (wav->isRunning()) {
    if (!wav->loop()) wav->stop();
  }
}

void setup() {
  Serial.begin(115200);

  // Initialize the RTC module
  Wire.begin();
  RTC.begin();
  //RTC.adjust(DateTime(F(__DATE__), F(__TIME__))); // Set the initial time (optional)
}

void loop() {
  DateTime now = RTC.now();

  // Check if it's the start of an hour (minute is 0) and in 12-hour format
  if (now.minute() == 0 && now.second() == 0) {
    if (now.hour() >= 1 && now.hour() <= 12) {  // Check if the hour is in the range of 1 to 12
      playChime();
    }
  }

  // Your additional code or tasks can go here

  // Add any other code you need to run in the loop
}

chime.h (2.4 MB)

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