I need a short beep for every minute of change. I wrote a separate function. The signal duration should be 50 ms, the rest of the time the emitter connected to the A1 contact should be silent.
A really working sketch is shown below:
uint32_t mysound; // Variable for storing time (duration of the sound signal)
uint32_t myTimer1;
uint32_t t; //Time that always increases
byte seconds; // Seconds
byte minutes; // Minutes
int k = 1;
void setup()
{
DDRC = B00000010; // Set pin A1 as output
// 76543210
Serial.begin(9600);
myTimer1 = millis();
}
void loop()
{
t = (millis() - myTimer1) / 1000; // Time in seconds
seconds = t % 60; // when 60 seconds are reached, it is reset to zero
minutes = t / 60 % 60; // Counts the minutes and drops to zero when 60 minutes are reached
Serial.println(seconds);
if (seconds == 0 && k)
{
sound();
}
if (seconds > 0) k = 1;
}
void sound()
{
mysound = millis();
while (millis() - mysound < 50)
{
PORTC = B00000010; // We set high voltage on pin A1 for a time of 50 ms
}
k = 0;
PORTC = B00000000;
}
doesn't work
is a meaningless description of what you observed ... please describe what happens ... also, describe what tests you performed to make sure that the piezo emitter works