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.7KB

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. 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 <PortMCP23S17.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. PortMCP23S17 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. PortMCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 );
  44. PortMCP23S17 portB(IOE_ADDR, 1, 0);
  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. The first parameteer of a Row constructor specifies the scanner.
  58. The second parameter of the Row constructor specifies the Row's strobePin.
  59. strobePin has one of two formats:
  60. * if refScanner a Scanner_uC, then strobePin is an Arduino pin number connected to this row
  61. * otherwise strobePin is a bit pattern, 1 indicating an IC pin connected to the row
  62. */
  63. /* ---------------- LEFT ROWS ------------------
  64. The left rows have a Scanner_uC and Arduino pin numbers to strobe.
  65. */
  66. Key* ptrsKeys_L0[] = { &s_1, &s_2 };
  67. const uint8_t KEY_COUNT_L0 = sizeof(ptrsKeys_L0)/sizeof(*ptrsKeys_L0);
  68. Row row_L0(scanner_L, 0, ptrsKeys_L0, KEY_COUNT_L0);
  69. Key* ptrsKeys_L1[] = { &s_a, &s_b };
  70. const uint8_t KEY_COUNT_L1 = sizeof(ptrsKeys_L1)/sizeof(*ptrsKeys_L1);
  71. Row row_L1(scanner_L, 1, ptrsKeys_L1, KEY_COUNT_L1);
  72. /* ---------------- RIGHT ROWS -----------------
  73. The right rows have a Scanner_IOE and pin bits to strobe.
  74. */
  75. Key* ptrsKeys_R0[] = { &s_3, &s_4 };
  76. const uint8_t KEY_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  77. Row row_R0(scanner_R, 1<<0, ptrsKeys_R0, KEY_COUNT_R0);
  78. Key* ptrsKeys_R1[] = { &s_c, &s_d };
  79. const uint8_t KEY_COUNT_R1 = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
  80. Row row_R1(scanner_R, 1<<1, ptrsKeys_R1, KEY_COUNT_R1);
  81. // ################### MAIN ####################
  82. void setup()
  83. {
  84. Keyboard.begin();
  85. scanner_R.begin();
  86. }
  87. void loop()
  88. {
  89. //left matrix
  90. row_L0.process();
  91. row_L1.process();
  92. //right matrix
  93. row_R0.process();
  94. row_R1.process();
  95. scanDelay.delay();
  96. //debug.print_scans_per_second();
  97. //debug.print_microseconds_per_scan();
  98. }