No Description
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.

common.cpp 866B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <Arduino.h>
  2. #include "config.h"
  3. #include "config_pins.h"
  4. unsigned long last_led_blink_time = 0;
  5. unsigned long beep_stop_time = 0;
  6. void async_beep(int time, int freq) {
  7. beep_stop_time = millis() + time;
  8. tone(BEEPER, freq);
  9. }
  10. void blocking_beep(int time, int freq, int repeat = 0) {
  11. for (int i = 0; i <= repeat; i++) {
  12. tone(BEEPER, freq);
  13. delay(time);
  14. noTone(BEEPER);
  15. if ((repeat > 0) && (i < repeat)) {
  16. delay(time);
  17. }
  18. }
  19. }
  20. void common_run(unsigned long t) {
  21. // stop async beep
  22. if ((beep_stop_time > 0) && (t > beep_stop_time)) {
  23. noTone(BEEPER);
  24. beep_stop_time = 0;
  25. }
  26. // blink heartbeat LED
  27. if ((t - last_led_blink_time) >= LED_BLINK_INTERVAL) {
  28. last_led_blink_time = millis();
  29. digitalWrite(LED_PIN, !digitalRead(LED_PIN));
  30. }
  31. }