123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
-
-
- #include "Marlin.h"
- #if HAS_BUZZER
- #include "buzzer.h"
- #include "ultralcd.h"
-
- void buzz(long duration, uint16_t freq) {
- if (freq > 0) {
- #if ENABLED(LCD_USE_I2C_BUZZER)
- lcd_buzz(duration, freq);
- #elif PIN_EXISTS(BEEPER)
- SET_OUTPUT(BEEPER_PIN);
- #if ENABLED(SPEAKER)
-
- unsigned int delay = 1000000 / freq / 2;
- int i = duration * freq / 1000;
- while (i--) {
- WRITE(BEEPER_PIN, HIGH);
- delayMicroseconds(delay);
- WRITE(BEEPER_PIN, LOW);
- delayMicroseconds(delay);
- }
- #else
- WRITE(BEEPER_PIN, HIGH);
- delay(duration);
- WRITE(BEEPER_PIN, LOW);
- #endif
- #else
- delay(duration);
- #endif
- }
- else {
- delay(duration);
- }
- }
- #endif
|