keybrd library is an open source library for creating custom-keyboard firmware.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

keybrd_4c_split_keyboard_with_IOE.ino 3.8KB

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