2015-06-17 16:31:14 +02: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 07:21:18 +02:00
|
|
|
#if ENABLED(LCD_USE_I2C_BUZZER)
|
2015-06-17 16:31:14 +02:00
|
|
|
lcd_buzz(duration, freq);
|
2015-07-31 07:39:27 +02:00
|
|
|
#elif defined(BEEPER) && BEEPER >= 0 // on-board buzzers have no further condition
|
2015-06-17 16:31:14 +02:00
|
|
|
SET_OUTPUT(BEEPER);
|
2015-07-24 23:19:09 +02:00
|
|
|
#ifdef SPEAKER // a speaker needs a AC ore a pulsed DC
|
|
|
|
//tone(BEEPER, freq, duration); // needs a PWMable pin
|
|
|
|
unsigned int delay = 1000000 / freq / 2;
|
|
|
|
int i = duration * freq / 1000;
|
|
|
|
while (i--) {
|
|
|
|
WRITE(BEEPER,HIGH);
|
|
|
|
delayMicroseconds(delay);
|
|
|
|
WRITE(BEEPER,LOW);
|
|
|
|
delayMicroseconds(delay);
|
|
|
|
}
|
|
|
|
#else // buzzer has its own resonator - needs a DC
|
|
|
|
WRITE(BEEPER, HIGH);
|
|
|
|
delay(duration);
|
|
|
|
WRITE(BEEPER, LOW);
|
|
|
|
#endif
|
2015-06-17 16:31:14 +02:00
|
|
|
#else
|
|
|
|
delay(duration);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delay(duration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|