const int buzzerPin = A2;
int buzzerState = LOW; // ledState used to set the LED
unsigned long previousMillis_1 = 0; // will store last time LED was updated
unsigned long previousMillis_2 = 0; // will store last time LED was updated
const long interval_1 = 337; // ON time
const long interval_2 = 1000 - 337; // OFF time
void setup() {
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW);
}
void loop() {
// here is where you'd put code that needs to be running all the time.
//
// and this checks if it is time to change the buzzer
unsigned long currentMillis = millis();
if (buzzerState == HIGH) {
if (currentMillis - previousMillis_1 >= interval_1) {
digitalWrite(buzzerPin, LOW);
previousMillis_2 = currentMillis;
buzzerState = LOW;
}
}
else { // buzzerState == LOW
if (currentMillis - previousMillis_2 >= interval_2) {
digitalWrite(buzzerPin, HIGH);
previousMillis_1 = currentMillis;
buzzerState = HIGH;
}
}
}