My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

buzzer.cpp 1021B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "Marlin.h"
  2. #if HAS_BUZZER
  3. #include "buzzer.h"
  4. #include "ultralcd.h"
  5. void buzz(long duration, uint16_t freq) {
  6. if (freq > 0) {
  7. #if ENABLED(LCD_USE_I2C_BUZZER)
  8. lcd_buzz(duration, freq);
  9. #elif PIN_EXISTS(BEEPER) // on-board buzzers have no further condition
  10. SET_OUTPUT(BEEPER_PIN);
  11. #if ENABLED(SPEAKER) // a speaker needs a AC ore a pulsed DC
  12. //tone(BEEPER_PIN, freq, duration); // needs a PWMable pin
  13. unsigned int delay = 1000000 / freq / 2;
  14. int i = duration * freq / 1000;
  15. while (i--) {
  16. WRITE(BEEPER_PIN, HIGH);
  17. delayMicroseconds(delay);
  18. WRITE(BEEPER_PIN, LOW);
  19. delayMicroseconds(delay);
  20. }
  21. #else // buzzer has its own resonator - needs a DC
  22. WRITE(BEEPER_PIN, HIGH);
  23. delay(duration);
  24. WRITE(BEEPER_PIN, LOW);
  25. #endif
  26. #else
  27. delay(duration);
  28. #endif
  29. }
  30. else {
  31. delay(duration);
  32. }
  33. }
  34. #endif