My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

buzzer.cpp 991B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "Marlin.h"
  2. #include "buzzer.h"
  3. #include "ultralcd.h"
  4. #if HAS_BUZZER
  5. void buzz(long duration, uint16_t freq) {
  6. if (freq > 0) {
  7. #ifdef LCD_USE_I2C_BUZZER
  8. lcd_buzz(duration, freq);
  9. #elif defined(BEEPER) && BEEPER >= 0 // on-board buzzers have no further condition
  10. SET_OUTPUT(BEEPER);
  11. #ifdef SPEAKER // a speaker needs a AC ore a pulsed DC
  12. //tone(BEEPER, 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,HIGH);
  17. delayMicroseconds(delay);
  18. WRITE(BEEPER,LOW);
  19. delayMicroseconds(delay);
  20. }
  21. #else // buzzer has its own resonator - needs a DC
  22. WRITE(BEEPER, HIGH);
  23. delay(duration);
  24. WRITE(BEEPER, LOW);
  25. #endif
  26. #else
  27. delay(duration);
  28. #endif
  29. }
  30. else {
  31. delay(duration);
  32. }
  33. }
  34. #endif