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

keybrd_4c_split_with_IOE.ino 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* keybrd_4c_split_with_IOE.ino
  2. This sketch:
  3. is a simple 1-layer keyboard
  4. runs on two matrices of a breadboard keyboard
  5. is annotated with a walk-through narrative
  6. This layout table shows left and right matrices:
  7. | Left | **0** | **1** | | Right | **0** | **1** |
  8. |:-----:|-------|-------|-|:-----:|-------|-------|
  9. | **1** | 1 | 2 | | **1** | 3 | 4 |
  10. | **0** | a | b | | **0** | c | d |
  11. */
  12. // ################## GLOBAL ###################
  13. // ================= INCLUDES ==================
  14. #include <ScanDelay.h>
  15. #include <Code_Sc.h>
  16. #include <Row.h>
  17. //left matrix
  18. #include <Scanner_uC.h>
  19. //right matrix
  20. #include <PortIOE.h>
  21. #include <PortWrite_MCP23S17.h>
  22. #include <PortRead_MCP23S17.h>
  23. #include <Scanner_IOE.h>
  24. // ============ SPEED CONFIGURATION ============
  25. ScanDelay scanDelay(9000);
  26. // ================ LEFT SCANNER ===============
  27. /*
  28. Left matrix rows work the same as the ones in keybrd_2_single-layer.ino
  29. */
  30. uint8_t readPins[] = {14, 15};
  31. const uint8_t READPIN_COUNT = sizeof(readPins)/sizeof(*readPins);
  32. Scanner_uC scanner_L(LOW, readPins, READPIN_COUNT);
  33. // =============== RIGHT SCANNER ===============
  34. /*
  35. The right matrix is scanned by an I/O expander.
  36. The I/O expander device address is configured by hardware pins.
  37. DEVICE_ADDR is a static variable of class PortIOE.
  38. */
  39. const uint8_t PortIOE::DEVICE_ADDR = 0x20; //MCP23S17 address with all 3 ADDR pins are grounded
  40. todo explain port num and shift notation <<
  41. /*
  42. port_B stobes the row while port_A reads the colums.
  43. port_A is assigned port identification number 0.
  44. port_A is assigned to portRead, which reads port_A pins 0 and 1.
  45. "<<" (bit shift left) and "|" (or) are bitwise operators.
  46. Pin numbers to be read are to the right of "1<<" and delimited by "|".
  47. */
  48. PortIOE port_A(0);
  49. PortRead_MCP23S17 portRead(port_A, 1<<0 | 1<<1 );
  50. /*
  51. port_B is assigned port identification number 1.
  52. port_B is assigned to portWrite.
  53. */
  54. PortIOE port_B(1);
  55. //PortWrite_MCP23S17 portWrite(port_B); //for LEDs todo
  56. PortWrite_MCP23S17 portWrite(port_B);
  57. Scanner_IOE scanner_R(LOW, portWrite, portRead);
  58. // =================== CODES ===================
  59. Code_Sc s_a(KEY_A);
  60. Code_Sc s_b(KEY_B);
  61. Code_Sc s_c(KEY_C);
  62. Code_Sc s_d(KEY_D);
  63. Code_Sc s_1(KEY_1);
  64. Code_Sc s_2(KEY_2);
  65. Code_Sc s_3(KEY_3);
  66. Code_Sc s_4(KEY_4);
  67. // =================== ROWS ====================
  68. /*
  69. Left row names contain the letter 'L', while right row names conatain the letter 'R'.
  70. The first parameteer of a Row constructor specifies the scanner.
  71. The second parameter of the Row constructor specifies the Row's strobePin.
  72. strobePin has one of two formats:
  73. * if refScanner a Scanner_uC, then strobePin is an Arduino pin number connected to this row
  74. * otherwise strobePin is a bit pattern, 1 indicating an IC pin connected to this row
  75. */
  76. // ---------------- LEFT ROWS ------------------
  77. /* The left rows have a Scanner_uC and Arduino pin numbers to strobe.
  78. */
  79. Key* ptrsKeys_L0[] = { &s_1, &s_2 };
  80. const uint8_t KEY_COUNT_L0 = sizeof(ptrsKeys_L0)/sizeof(*ptrsKeys_L0);
  81. Row row_L0(scanner_L, 0, ptrsKeys_L0, KEY_COUNT_L0);
  82. Key* ptrsKeys_L1[] = { &s_a, &s_b };
  83. const uint8_t KEY_COUNT_L1 = sizeof(ptrsKeys_L1)/sizeof(*ptrsKeys_L1);
  84. Row row_L1(scanner_L, 1, ptrsKeys_L1, KEY_COUNT_L1);
  85. // ---------------- RIGHT ROWS -----------------
  86. /*
  87. The right rows have a Scanner_IOE and pin bits to strobe.
  88. */
  89. Key* ptrsKeys_R0[] = { &s_3, &s_4 };
  90. const uint8_t KEY_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  91. Row row_R0(scanner_R, 1<<0, ptrsKeys_R0, KEY_COUNT_R0);
  92. Key* ptrsKeys_R1[] = { &s_c, &s_d };
  93. const uint8_t KEY_COUNT_R1 = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
  94. Row row_R1(scanner_R, 1<<1, ptrsKeys_R1, KEY_COUNT_R1);
  95. // ################### MAIN ####################
  96. void setup()
  97. {
  98. delay(7000); //todo
  99. Keyboard.begin();
  100. scanner_R.begin();
  101. }
  102. void loop()
  103. {
  104. //left matrix
  105. row_L0.process();
  106. row_L1.process();
  107. //right matrix
  108. row_R0.process();
  109. row_R1.process();
  110. scanDelay.delay();
  111. //debug.print_scans_per_second();
  112. //debug.print_microseconds_per_scan();
  113. }