const int BUTTON_PIN = 4;
const int BUZZER_PIN = 3;
const int LED_PIN = 5;
int buttonState = HIGH;
int buzzerState = LOW;
unsigned long previousMillis = 0;
unsigned long previousMillis1 = 0;
const long interval = 100;
void setup() {
Serial.begin(9600);
PORTD = (_BV(BUTTON_PIN));
DDRD |= ( _BV(BUZZER_PIN));
}
void loop() {
buttonState = (PIND & _BV(BUTTON_PIN));
buzzerState = (PIND & _BV(BUZZER_PIN));
if (buttonState == LOW && buzzerState == LOW) {
previousMillis = millis();
while((millis() - previousMillis) <= interval)
{
}
PORTD |= _BV(BUZZER_PIN);
PORTD |= _BV(LED_PIN);
}
if (buttonState == LOW && buzzerState != LOW)
{
previousMillis1 = millis();
while((millis() - previousMillis1) <= interval)
{
}
PORTD &= ~_BV(BUZZER_PIN);
PORTD &= ~_BV(LED_PIN);
}
}