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_4b_split_keyboard_with_shift_registers.ino 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* tutorial_4b_split_keyboard_with_shift_registers.ino
  2. Tested on Teensy LC and two 74HC165 shift registers.
  3. The right matrix has 2 shift registers daisy chained.
  4. Layout Layout
  5. | Left |**0**| | Right |**0**|**1**|**2**|**3**|**4**|**5**|**6**|
  6. |:-----:|-----| |:-----:|-----|-----|-----|-----|-----|-----|-----|
  7. | **0** | x | | **0** | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
  8. | **1** | y | | **1** | a | b | c | d | e | f | g |
  9. */
  10. // ################## GLOBAL ###################
  11. // ================= INCLUDES ==================
  12. #include <ScanDelay.h>
  13. #include <Code_Sc.h>
  14. //Left matrix
  15. #include <Scanner_uC.h>
  16. #include <Row.h>
  17. //Right matrix
  18. #include <Scanner_ShiftRegsPISOSingleRow.h>
  19. // =============== CONFIGURATION ===============
  20. ScanDelay scanDelay(9000);
  21. // =================== CODES ===================
  22. Code_Sc s_a(KEY_A);
  23. Code_Sc s_b(KEY_B);
  24. Code_Sc s_c(KEY_C);
  25. Code_Sc s_d(KEY_D);
  26. Code_Sc s_e(KEY_E);
  27. Code_Sc s_f(KEY_F);
  28. Code_Sc s_g(KEY_G);
  29. Code_Sc s_x(KEY_X);
  30. Code_Sc s_y(KEY_Y);
  31. Code_Sc s_0(KEY_0);
  32. Code_Sc s_1(KEY_1);
  33. Code_Sc s_2(KEY_2);
  34. Code_Sc s_3(KEY_3);
  35. Code_Sc s_4(KEY_4);
  36. Code_Sc s_5(KEY_5);
  37. Code_Sc s_6(KEY_6);
  38. // ================= SCANNERS ==================
  39. // --------------- LEFT SCANNER ----------------
  40. uint8_t readPins_L[] = {14};
  41. uint8_t readPinCount_L = sizeof(readPins_L)/sizeof(*readPins_L);
  42. Scanner_uC scanner_L(LOW, readPins_L, readPinCount_L); //active LOW
  43. /* --------------- RIGHT SCANNER ---------------
  44. use slaveSelect pin SS (Arduino pin 10) for fastest scan
  45. */
  46. Scanner_ShiftRegsPISOSingleRow scanner_R(HIGH, SS, 2); //active HIGH
  47. // =================== ROWS ====================
  48. // ----------------- LEFT ROWS -----------------
  49. Key* ptrsKeys_L0[] = { &s_x };
  50. uint8_t KEY_COUNT_L0 = sizeof(ptrsKeys_L0)/sizeof(*ptrsKeys_L0);
  51. Row row_L0(scanner_L, 0, ptrsKeys_L0, KEY_COUNT_L0);
  52. Key* ptrsKeys_L1[] = { &s_y };
  53. uint8_t KEY_COUNT_L1 = sizeof(ptrsKeys_L1)/sizeof(*ptrsKeys_L1);
  54. Row row_L1(scanner_L, 1, ptrsKeys_L1, KEY_COUNT_L1);
  55. // ----------------- RIGHT ROWS ----------------
  56. Key* ptrsKeys_R0[] = { &s_6, &s_5, &s_4, &s_3, //shift register on right
  57. &s_c, &s_d, &s_e, &s_f,
  58. &s_2, &s_1, &s_0, &s_g, //shift register on left
  59. &s_a, &s_b }; //unused input pins are grounded
  60. Row row_R0(scanner_R, 0, ptrsKeys_R0, sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0));
  61. // ################### MAIN ####################
  62. void setup()
  63. {
  64. Keyboard.begin();
  65. scanner_R.begin();
  66. }
  67. void loop()
  68. {
  69. //left matrix
  70. row_L0.process();
  71. row_L1.process();
  72. //right matrix
  73. row_R0.process();
  74. scanDelay.delay();
  75. }