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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* tutorial_4a_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 <SPI.h>//needed?? todo
  19. #include <Scanner_ShiftRegsPISOSingleRow.h>
  20. // =============== CONFIGURATION ===============
  21. ScanDelay scanDelay(9000);
  22. // =================== CODES ===================
  23. Code_Sc s_a(KEY_A);
  24. Code_Sc s_b(KEY_B);
  25. Code_Sc s_c(KEY_C);
  26. Code_Sc s_d(KEY_D);
  27. Code_Sc s_e(KEY_E);
  28. Code_Sc s_f(KEY_F);
  29. Code_Sc s_g(KEY_G);
  30. Code_Sc s_x(KEY_X);
  31. Code_Sc s_y(KEY_Y);
  32. Code_Sc s_0(KEY_0);
  33. Code_Sc s_1(KEY_1);
  34. Code_Sc s_2(KEY_2);
  35. Code_Sc s_3(KEY_3);
  36. Code_Sc s_4(KEY_4);
  37. Code_Sc s_5(KEY_5);
  38. Code_Sc s_6(KEY_6);
  39. // =============== LEFT MATRIX =================
  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. //rows
  44. Key* ptrsKeys_L0[] = { &s_x };
  45. uint8_t KEY_COUNT_L0 = sizeof(ptrsKeys_L0)/sizeof(*ptrsKeys_L0);
  46. Row row_L0(scanner_L, 0, ptrsKeys_L0, KEY_COUNT_L0);
  47. Key* ptrsKeys_L1[] = { &s_y };
  48. uint8_t KEY_COUNT_L1 = sizeof(ptrsKeys_L1)/sizeof(*ptrsKeys_L1);
  49. Row row_L1(scanner_L, 1, ptrsKeys_L1, KEY_COUNT_L1);
  50. // =============== RIGHT MATRIX ================
  51. //use slaveSelect pin SS (Arduino pin 10) for fastest scan
  52. Scanner_ShiftRegsPISOSingleRow scanner_R(HIGH, SS, 2); //active HIGH
  53. //rows
  54. Key* ptrsKeys_R0[] = { &s_6, &s_5, &s_4, &s_3, //shift register on right
  55. &s_c, &s_d, &s_e, &s_f,
  56. &s_2, &s_1, &s_0, &s_g, //shift register on left
  57. &s_a, &s_b }; //unused input pins are grounded
  58. Row row_R0(scanner_R, 0, ptrsKeys_R0, sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0));
  59. // ################### MAIN ####################
  60. void setup()
  61. {
  62. Keyboard.begin();
  63. SPI.begin();//todo move to begin()
  64. scanner_R.begin();
  65. }
  66. void loop()
  67. {
  68. //left matrix
  69. row_L0.process();
  70. row_L1.process();
  71. //right matrix
  72. row_R0.process();
  73. scanDelay.delay();
  74. }