Still test Buzzer, a simple sketch as attached, AA1 works normally, AA works abnormally or even no sound, why?
The reason to use millis is need a beep short and long interval.
/*
test buzzer with millis
*/
#include <toneAC.h>
#define INTERVAL_MESSAGE_AAa 5000
#define INTERVAL_MESSAGE_AA 5000
#define INTERVAL_MESSAGE_00 10000
#define INTERVAL_MESSAGE_BB 2000
unsigned long previousMillis5 = 0;// will store last time LED was updated
const long interval5 = 5000; // interval at which to blink (milliseconds)
unsigned long currentMillis5 = millis();
unsigned long time_AAa = 0;
unsigned long time_AA = 0;
unsigned long time_00 = 0;
unsigned long time_BB = 0;
int Buzzer = 12;
int numTones = 10;
int tones[] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440};
// mid C C# D D# E F F# G G# A
void setup()
{
Serial.begin(9600);
pinMode(Buzzer, OUTPUT);
}
void loop()
{
BuzzerAA1();
}
void BuzzerAA() { // normal preparing, operator guide the Robot approaching the bin need be taken.
if (millis() >= time_AA + INTERVAL_MESSAGE_AA) {
time_AA += INTERVAL_MESSAGE_AA;
toneAC(Buzzer, 1000);
delay(10);
toneAC();
delay(100);
toneAC(Buzzer, 1000);
delay(10);
toneAC();
}
Serial.println("AA");
}
void BuzzerAA1() { // normal preparing, operator guide the Robot approaching the bin need be taken.
for (int i = 0; i < numTones; i++)
{
toneAC(Buzzer, tones[i]);
delay(500);
}
noToneAC();
Serial.println("AA1");
}