How to implement tone() Function after completion of PWM

I am writing a code for a laboratory equipment in which I am using a 'Robotdyne AC dimmer' module with Arduino UNO board. In this I intend to operate an electromagnet ON/OFF at defined power-level (say 50%) for predefined time duration (say 1000 seconds). Once the operation of electromagnet is over, I want to acknowledge the operation complete by playing a buzzer sound.

However, when I use the tone() function, I get the compilation error because both PWM and buzzer use the same timer.

  1. How can I implement the buzzer sound after the electromagnet operation is complete?
  2. When the PWM of AC dimmer module and tone functions are intended to operate sequentially and not simultaneously why there is a compiler issue?
  3. How can I detach the AC dimmer module from timer when operation is complete, so that buzzer can use it?
#include <RBDdimmer.h>
# define buzzer A0 // +ve of buzzer-pin to A0 and -ve to GND
#define dimmerPWM  4 // Robotdyn AC module PWM to D4. Zero-Crossing default connected to D2,No declaration for this needed.
dimmerLamp Electromagnet(dimmerPWM); 

unsigned int TotalTime = 1000; // this time is in seconds
unsigned int OnInterval = 1000; // this time is in milliseconds
unsigned int OffInterval = 1000; // this time is in milliseconds
byte Power = 50 ; // Dimmer Power value for Electromagnet to Operate, can be set as 0-100%.
void setup() {
  Electromagnet.begin(NORMAL_MODE, OFF); // Initialize the Electromagnet Dimmer Circuit
}
void loop() {
 Electromagnet.setPower(Power);
 unsigned int StartTime = millis() / 1000;   // Time in seconds
 unsigned int CurrentTime = StartTime; // Time in Seconds
 unsigned int TimeElapsed = StartTime - CurrentTime;
  while (TimeElapsed < TotalTime) {
    Electromagnet.setState(ON);
    delay (OnInterval);
    Electromagnet.setState(OFF);
    delay (OffInterval);
    CurrentTime = millis() / 1000;
    TimeElapsed = StartTime-CurrentTime;
  }
tone(buzzer, 1000, 2000); //Code compiles when this function is commented.
}

Thanks

Robotdyn AC dimmer module link: (https://robotdyn.com/ac-light-dimmer-module-1-channel-3-3v-5v-logic-ac-50-60hz-220v-110v.html.

A tone is nothing more than a repetitive change from LOW to HIGH and back. You can basically implement that with a digitalWrite; if you can't achieve a high-enough frequency, you can use direct port manipulation.
2)
For your processor, both libraries use the same interrupt vector; and you can only define an interrupt vector once.
3)
No idea. You can hack the libraries and change one of them to user a different timer.

Take a look at the NewTone library. It uses Timer1. There is also a TimerFreeTone library.

Some documentation is here
https://bitbucket.org/teckel12/arduino-new-tone/wiki/Home

https://bitbucket.org/teckel12/arduino-timer-free-tone/wiki/Home

Or replace your passive buzzer with an active one.