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_3e_sublayerNestedScSc.ino 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* keybrd_3e_sublayerNestedScSc.ino
  2. This sketch:
  3. is firmware for layout 2 layers plus 1 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** |Normal | 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_LayeredScSc.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. // ---------------- LAYER CODE -----------------
  31. enum layers { NORMAL, SYM };
  32. LayerState layerState;
  33. Code_LayerLock l_normal(NORMAL, layerState);
  34. Code_LayerLock l_sym(SYM, layerState);
  35. LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
  36. // ---------------- SUBLAYER CODE --------------
  37. enum subLayers { SUBSYM, SUBNUM };
  38. LayerState sublayerState;
  39. Code_LayerHold l_num(SUBNUM, sublayerState);
  40. LayerStateInterface& Key_LayeredScSc::refLayerState = sublayerState;
  41. // ---------------- SCAN CODES -----------------
  42. Code_Sc s_a(KEY_A);
  43. Code_Sc s_b(KEY_B);
  44. Code_Sc s_c(KEY_C);
  45. Code_Sc s_minus(KEY_MINUS);
  46. Code_Sc s_equal(KEY_EQUAL);
  47. Code_Sc s_enter(KEY_ENTER);
  48. Code_Sc s_1(KEY_1);
  49. /* =================== KEYS ====================
  50. The key k_sub00 contains codes for layerIds SUBSYM and SUBNUM.
  51. Key_LayeredScSc takes two scancode arguments.
  52. (The Num sublayer only has one key because small example. Usually sublayers have multiple keys.)
  53. */
  54. Key_LayeredScSc sub_00(KEY_MINUS, KEY_1);
  55. /*
  56. k_sub00 is nested in k_00.
  57. The key k_00 contains code and key for layerIds NORMAL and SYS.
  58. Notice that k_sub00 is of type Key_LayeredKeys1, while k_00 is of type Key_LayeredKeys.
  59. k_sub00 and k_00 are associated with distinct LayerStates.
  60. */
  61. Key* const ptrsCodes_00[] = { &s_a, &sub_00 };
  62. Key_LayeredKeys k_00(ptrsCodes_00);
  63. Key* const ptrsCodes_01[] = { &s_b, &s_equal };
  64. Key_LayeredKeys k_01(ptrsCodes_01);
  65. Key* const ptrsCodes_02[] = { &s_c, &l_num };
  66. Key_LayeredKeys k_02(ptrsCodes_02);
  67. // =================== ROWS ====================
  68. Key* const ptrsKeys_0[] = { &k_00, &k_01, &k_02 };
  69. uint8_t keyCount_0 = sizeof(ptrsKeys_0)/sizeof(*ptrsKeys_0);
  70. Row row_0(scanner, 0, ptrsKeys_0, keyCount_0);
  71. Key* const ptrsKeys_1[] = { &l_normal, &l_sym, &s_enter };
  72. uint8_t keyCount_1 = sizeof(ptrsKeys_1)/sizeof(*ptrsKeys_1);
  73. Row row_1(scanner, 1, ptrsKeys_1, keyCount_1);
  74. // ################### MAIN ####################
  75. void setup()
  76. {
  77. Keyboard.begin();
  78. }
  79. void loop()
  80. {
  81. row_0.process();
  82. row_1.process();
  83. scanDelay.delay();
  84. }