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_3d_sublayerNestedKeys.ino 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* keybrd_3d_sublayerNested.ino
  2. This sketch:
  3. is firmware for layout with two layers plus one sublayer.
  4. runs on the first three columns of a breadboard keyboard
  5. | Layout | **0** | **1** | **2** |
  6. |:------:|:-----:|:-----:|:-----:|
  7. | **0** | a - 1 | b = | c Num |
  8. | **1** | Alpha | Sym | Enter |
  9. */
  10. // ################## GLOBAL ###################
  11. // ================= INCLUDES ==================
  12. //Keys
  13. #include <Code_Sc.h>
  14. #include <LayerState.h>
  15. #include <Code_LayerLock.h>
  16. #include <Code_LayerHold.h>
  17. #include <Key_LayeredKeys.h>
  18. #include <Key_LayeredKeys1.h>
  19. //Matrix
  20. #include <Row.h>
  21. #include <Scanner_uC.h>
  22. #include <ScanDelay.h>
  23. // ============ SPEED CONFIGURATION ============
  24. ScanDelay scanDelay(9000);
  25. // ================== SCANNER ==================
  26. uint8_t readPins[] = {14, 15, 16};
  27. uint8_t readPinCount = sizeof(readPins)/sizeof(*readPins);
  28. Scanner_uC scanner(LOW, readPins, readPinCount);
  29. /* =================== CODES ===================
  30. Each LayerState object can manage one layer group. This sketch uses two LayerState objects.
  31. */
  32. // ---------------- LAYER GROUP ----------------
  33. enum layers { ALPHA, SYM };
  34. /*
  35. groupState keeps track of a layer group's active layer.
  36. */
  37. LayerState groupState;
  38. /*
  39. groupState is assigned to layers ALPHA and SYM.
  40. */
  41. Code_LayerLock l_alpha(ALPHA, groupState);
  42. Code_LayerLock l_sym(SYM, groupState);
  43. /*
  44. groupState manages a layer group delineated by all layers that are in Key_LayeredKeys objects.
  45. */
  46. LayerStateInterface& Key_LayeredKeys::refLayerState = groupState;
  47. // --------------- LAYER SUBGROUP --------------
  48. enum subLayers { SUBSYM, SUBNUM };
  49. /*
  50. subgroupState keeps track of a layer subgroup's active layer.
  51. */
  52. LayerState subgroupState;
  53. /*
  54. subgroupState is assigned to layer SUBNUM.
  55. subgroupState also has a default layer 0, which implicitly is layer SUBSYM.
  56. */
  57. Code_LayerHold l_num(SUBNUM, subgroupState);
  58. /*
  59. Key_LayeredKeys and Key_LayeredKeys1 are identical classes with distinct static refLayerState.
  60. subgroupState manages a layer group delineated by all layers that are in Key_LayeredKeys1 objects.
  61. */
  62. LayerStateInterface& Key_LayeredKeys1::refLayerState = subgroupState;
  63. // ----------------- SCANCODES -----------------
  64. Code_Sc s_a(KEY_A);
  65. Code_Sc s_b(KEY_B);
  66. Code_Sc s_c(KEY_C);
  67. Code_Sc s_minus(KEY_MINUS);
  68. Code_Sc s_equal(KEY_EQUAL);
  69. Code_Sc s_enter(KEY_ENTER);
  70. Code_Sc s_1(KEY_1);
  71. /* =================== KEYS ====================
  72. k_sub00 contains codes for sub layers SUBSYM and SUBNUM.
  73. k_sub00 gets it's active layer from subgroupState.
  74. (The Num sublayer only has one key because small example. Usually sublayers have multiple keys.)
  75. */
  76. Key* const ptrsKeys_sub00[] = { &s_minus, &s_1 };
  77. Key_LayeredKeys1 k_sub00(ptrsKeys_sub00);
  78. /*
  79. k_00 contains code and key for layers ALPHA and SYM.
  80. k_00 gets it's active layer from groupState.
  81. k_sub00 is nested in layer SYM.
  82. */
  83. Key* const ptrsKeys_00[] = { &s_a, &k_sub00 };
  84. Key_LayeredKeys k_00(ptrsKeys_00);
  85. Key* const ptrsKeys_01[] = { &s_b, &s_equal };
  86. Key_LayeredKeys k_01(ptrsKeys_01);
  87. Key* const ptrsKeys_02[] = { &s_c, &l_num };
  88. Key_LayeredKeys k_02(ptrsKeys_02);
  89. // =================== ROWS ====================
  90. Key* const ptrsKeys_0[] = { &k_00, &k_01, &k_02 };
  91. uint8_t keyCount_0 = sizeof(ptrsKeys_0)/sizeof(*ptrsKeys_0);
  92. Row row_0(scanner, 0, ptrsKeys_0, keyCount_0);
  93. Key* const ptrsKeys_1[] = { &l_alpha, &l_sym, &s_enter };
  94. uint8_t keyCount_1 = sizeof(ptrsKeys_1)/sizeof(*ptrsKeys_1);
  95. Row row_1(scanner, 1, ptrsKeys_1, keyCount_1);
  96. // ################### MAIN ####################
  97. void setup()
  98. {
  99. }
  100. void loop()
  101. {
  102. row_0.process();
  103. row_1.process();
  104. scanDelay.delay();
  105. }