My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

buzzer.cpp 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "Marlin.h"
  23. #if HAS_BUZZER
  24. #include "buzzer.h"
  25. #include "ultralcd.h"
  26. void buzz(long duration, uint16_t freq) {
  27. if (freq > 0) {
  28. #if ENABLED(LCD_USE_I2C_BUZZER)
  29. lcd_buzz(duration, freq);
  30. #elif PIN_EXISTS(BEEPER) // on-board buzzers have no further condition
  31. SET_OUTPUT(BEEPER_PIN);
  32. #if ENABLED(SPEAKER) // a speaker needs a AC ore a pulsed DC
  33. //tone(BEEPER_PIN, freq, duration); // needs a PWMable pin
  34. unsigned int delay = 1000000 / freq / 2;
  35. int i = duration * freq / 1000;
  36. while (i--) {
  37. WRITE(BEEPER_PIN, HIGH);
  38. delayMicroseconds(delay);
  39. WRITE(BEEPER_PIN, LOW);
  40. delayMicroseconds(delay);
  41. }
  42. #else // buzzer has its own resonator - needs a DC
  43. WRITE(BEEPER_PIN, HIGH);
  44. delay(duration);
  45. WRITE(BEEPER_PIN, LOW);
  46. #endif
  47. #else
  48. delay(duration);
  49. #endif
  50. }
  51. else {
  52. delay(duration);
  53. }
  54. }
  55. #endif