Help with building an alarm clock with fading lights, music and a touch screen

Thank you for the reply!
I edited my post. This looks much better :slight_smile:

As an answer to your question:
I used the code I found in a tutorial and on github, which both use software serial and pins 10 and 11.

As the pins 10 and 11 are taken by the touch screen in my project, my guess was to use PWM pins. but as I discover now, these are not the same as tx and rx pins and 47 isn't even a PWM pin.
But even with this the mp3 in itself to works quite well with simple play, pause, next and back commands. The volume control is my struggle. It did work with a delay function like this:

  myDFPlayer.play(1);
  brightness = 30;
  analogWrite(led, brightness);
  delay(5000);
  myDFPlayer.volume(6);
  brightness = 60;
  analogWrite(led, brightness);
  delay(5000);
  myDFPlayer.volume(8);
  brightness = 90;
  analogWrite(led, brightness);
  delay(5000);
  myDFPlayer.volume(10);
  brightness = 120;
  analogWrite(led, brightness);
  delay(5000);
  myDFPlayer.volume(15);
  delay(5000);
  brightness = 5;
  analogWrite(led, brightness);
  myDFPlayer.volume(2);

But I think this is not the way to go with building this, as it is quite an ugly long code and there are a lot of delays in there, which I guess will not allow to build a snooze / off button.

If you suggest to use other ports I would be happy to try it out! However, the tft touch screen shield blocks ports 0-13 and a0-a5.

1 Like