keybrd library is an open source library for creating custom-keyboard firmware.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
Это архивный репозиторий. Вы можете его клонировать или просматривать файлы, но не вносить изменения или открывать задачи/запросы на слияние.

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef SCANDELAY_H
  2. #define SCANDELAY_H
  3. #include <Arduino.h>
  4. #include <inttypes.h>
  5. /* ScanDelay() delay's scan to give switches time to debounce.
  6. DELAY_MICROSECONDS explained
  7. ----------------------------
  8. A keyboard with a faster scan rate responds faster.
  9. Follow these step to tune DELAY_MICROSECONDS for maximum scan rate for a given SAMPLE_COUNT:
  10. Intantiate DELAY_MICROSECONDS in your sketch:
  11. ScanDelay scanDelay(1000);
  12. Add this to the sketch's loop() function:
  13. debug.printMicrosecondsPerScan();
  14. Compile and load the sketch into the microcontroller; microseconds_per_scan is printed every second.
  15. Adjust the value of DELAY_MICROSECONDS and repeat until:
  16. debug.printMicrosecondsPerScan() <= DEBOUNCE_TIME / SAMPLE_COUNT
  17. DEBOUNCE_TIME can be obtained from the switch's datasheet. Some switch bounce times are:
  18. Cherry MX specifies 5msec bounce time http://www.cherrycorp.com/english/switches/key/mx.htm
  19. hasu measured Cherry MX bounce times .3ms to 1.4ms http://geekhack.org/index.php?topic=42385.0
  20. Tactile switch MJTP series bounce 10 ms http://www.apem.com/files/apem/brochures/MJTP_6MM.pdf
  21. The largest allowable DELAY_MICROSECONDS is 65535 (65.535 ms).
  22. Avoid sampling the switch input at a rate synchronous to events in the environment
  23. that might create periodic EMI. For instance, 50 and 60 Hz.
  24. Polling I2C may slow the scan rate enough so that no additional delay is needed
  25. and scanDelay(0) can be omitted from the loop().
  26. Could put delay directly in loop(), but then it's harder to finding this documentation.
  27. delay(5);
  28. */
  29. class ScanDelay
  30. {
  31. private:
  32. const unsigned int DELAY_MICROSECONDS; //delay each loop() for debouncing
  33. public:
  34. ScanDelay(const unsigned int DELAY_MICROSECONDS): DELAY_MICROSECONDS(DELAY_MICROSECONDS) {}
  35. void delay();
  36. };
  37. #endif