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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. Controller I/O expander
  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 <Port_MCP23S17.h>
  20. #include <Scanner_IOE.h>
  21. // ============ SPEED CONFIGURATION ============
  22. ScanDelay scanDelay(9000);
  23. /* ================ LEFT SCANNER ===============
  24. Left matrix rows work the same as the ones in keybrd_2_single-layer.ino
  25. */
  26. uint8_t readPins[] = {14, 15};
  27. const uint8_t readPinCount = sizeof(readPins)/sizeof(*readPins);
  28. Scanner_uC scanner_L(LOW, readPins, readPinCount);
  29. /* =============== RIGHT SCANNER ===============
  30. The right matrix is scanned by an I/O expander.
  31. The MCP23S17 address is set by grounding or powering pins.
  32. */
  33. const uint8_t IOE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded
  34. /*
  35. Normally all strobe pins are on one port, and all the read pins are on the other port.
  36. In this example, portB stobes the row while portA reads the colums.
  37. Port_MCP23S17 constructor parameters are: deviceAddr, portNum, readPins.
  38. readPins is a bit pattern, where 0=output, 1=input.
  39. In portA, the first two pins are set to input for reading.
  40. "<<" (bit shift left) and "|" (OR) are bitwise operators.
  41. Pin numbers to be read are to the right of "1<<" and delimited by "|".
  42. */
  43. Port_MCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 ); //for read
  44. Port_MCP23S17 portB(IOE_ADDR, 1, 0); //for strobe
  45. Scanner_IOE scanner_R(LOW, portB, portA);
  46. // =================== CODES ===================
  47. Code_Sc s_a(KEY_A);
  48. Code_Sc s_b(KEY_B);
  49. Code_Sc s_c(KEY_C);
  50. Code_Sc s_d(KEY_D);
  51. Code_Sc s_1(KEY_1);
  52. Code_Sc s_2(KEY_2);
  53. Code_Sc s_3(KEY_3);
  54. Code_Sc s_4(KEY_4);
  55. /* =================== ROWS ====================
  56. Left row names contain the letter 'L', while right row names conatain the letter 'R'.
  57. Row constructor parameters are: scanner, strobePin, ptrsKeys[], keyCount.
  58. strobePin has one of two formats:
  59. * if strobe pin is on uC (strobe for Scanner_uC or Scanner_ShiftRegsRead),
  60. then strobePin is an Arduino pin number connected to this row.
  61. * if strobe pin is on I/O expander (strobe for Scanner_IOE), then strobePin is bit pattern,
  62. 1 indicating the I/O expander pin connected to this row
  63. */
  64. /* ---------------- LEFT ROWS ------------------
  65. The left rows have a Scanner_uC and Arduino pin numbers to strobe.
  66. */
  67. Key* ptrsKeys_L0[] = { &s_1, &s_2 };
  68. const uint8_t KEY_COUNT_L0 = sizeof(ptrsKeys_L0)/sizeof(*ptrsKeys_L0);
  69. Row row_L0(scanner_L, 0, ptrsKeys_L0, KEY_COUNT_L0);
  70. Key* ptrsKeys_L1[] = { &s_a, &s_b };
  71. const uint8_t KEY_COUNT_L1 = sizeof(ptrsKeys_L1)/sizeof(*ptrsKeys_L1);
  72. Row row_L1(scanner_L, 1, ptrsKeys_L1, KEY_COUNT_L1);
  73. /* ---------------- RIGHT ROWS -----------------
  74. The right rows have a Scanner_IOE and pin bits to strobe.
  75. */
  76. Key* ptrsKeys_R0[] = { &s_3, &s_4 };
  77. const uint8_t KEY_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  78. Row row_R0(scanner_R, 1<<0, ptrsKeys_R0, KEY_COUNT_R0);
  79. Key* ptrsKeys_R1[] = { &s_c, &s_d };
  80. const uint8_t KEY_COUNT_R1 = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
  81. Row row_R1(scanner_R, 1<<1, ptrsKeys_R1, KEY_COUNT_R1);
  82. // ################### MAIN ####################
  83. void setup()
  84. {
  85. Keyboard.begin();
  86. scanner_R.begin();
  87. }
  88. void loop()
  89. {
  90. //left matrix
  91. row_L0.process();
  92. row_L1.process();
  93. //right matrix
  94. row_R0.process();
  95. row_R1.process();
  96. scanDelay.delay();
  97. //debug.printScansPerSecond();
  98. //debug.printMicrosecondsPerScan();
  99. }