/* Program 2-5 send 440 Hz signal to the buzzer on Arduino * This program toggles pin 6 at 440 Hz using 1136 us delay * between toggles. Pin 6 is connected to a buzzer on the board. */ const int BUZZER = 6; const int HALF_PERIOD = 1000000 / 440 / 2; void setup() { /* initialize the digital pin as an output */ pinMode(BUZZER, OUTPUT); } void loop() { for (int i = 0; i < 440; i++) { digitalWrite(BUZZER, HIGH); /* turn the signal to buzzer high */ delayMicroseconds(HALF_PERIOD); /* wait for half cycle */ digitalWrite(BUZZER, LOW); /* turn the signal to buzzer low */ delayMicroseconds(HALF_PERIOD); /* wait for half cycle */ } delay(1000); }