2015-06-17 14:31:14 +00:00
|
|
|
#include "Marlin.h"
|
|
|
|
#include "buzzer.h"
|
|
|
|
#include "ultralcd.h"
|
|
|
|
|
|
|
|
#if HAS_BUZZER
|
|
|
|
void buzz(long duration, uint16_t freq) {
|
|
|
|
if (freq > 0) {
|
2015-07-31 05:21:18 +00:00
|
|
|
#if ENABLED(LCD_USE_I2C_BUZZER)
|
2015-06-17 14:31:14 +00:00
|
|
|
lcd_buzz(duration, freq);
|
2015-07-31 06:19:11 +00:00
|
|
|
#elif PIN_EXISTS(BEEPER) // on-board buzzers have no further condition
|
|
|
|
SET_OUTPUT(BEEPER_PIN);
|
2015-08-03 19:30:37 +00:00
|
|
|
#if ENABLED(SPEAKER) // a speaker needs a AC ore a pulsed DC
|
2015-07-31 06:19:11 +00:00
|
|
|
//tone(BEEPER_PIN, freq, duration); // needs a PWMable pin
|
2015-07-24 21:19:09 +00:00
|
|
|
unsigned int delay = 1000000 / freq / 2;
|
|
|
|
int i = duration * freq / 1000;
|
|
|
|
while (i--) {
|
2015-07-31 06:19:11 +00:00
|
|
|
WRITE(BEEPER_PIN, HIGH);
|
2015-07-24 21:19:09 +00:00
|
|
|
delayMicroseconds(delay);
|
2015-07-31 06:19:11 +00:00
|
|
|
WRITE(BEEPER_PIN, LOW);
|
2015-07-24 21:19:09 +00:00
|
|
|
delayMicroseconds(delay);
|
|
|
|
}
|
|
|
|
#else // buzzer has its own resonator - needs a DC
|
2015-07-31 06:19:11 +00:00
|
|
|
WRITE(BEEPER_PIN, HIGH);
|
2015-07-24 21:19:09 +00:00
|
|
|
delay(duration);
|
2015-07-31 06:19:11 +00:00
|
|
|
WRITE(BEEPER_PIN, LOW);
|
2015-07-24 21:19:09 +00:00
|
|
|
#endif
|
2015-06-17 14:31:14 +00:00
|
|
|
#else
|
|
|
|
delay(duration);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delay(duration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|