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_3c_sublayerNull.ino 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* keybrd_3c_sublayerNull.ino
  2. This sketch:
  3. is firmware for a simple 2-layer keyboard
  4. runs on the first two rows and columns of a breadboard keyboard
  5. | Layout | **0** | **1** | **2** |
  6. |:------:|:-----:|:-----:|:-----:|
  7. | **0** | a - 1 | b = | c Num |
  8. | **1** |Normal | Sym | Enter |
  9. normal layer keys are a b c
  10. sym layer keys are brackets [ ] and num
  11. num layer keys are 6 7
  12. The num layer key is located on the sym layer
  13. num layer is active while holding sym+num
  14. Each cell in the table's body represents a key.
  15. The layered keys in column 1 have two layers; one character for each layer.
  16. Letters 'a' and 'b' are on the normal layer. Numbers '1' and '2' are on the fn layer.
  17. Holding the fn key down makes it the active layer. Releasing the fn key restores the normal layer.
  18. */
  19. // ################## GLOBAL ###################
  20. // ================= INCLUDES ==================
  21. //Keys
  22. #include <Code_Sc.h>
  23. #include <Code_Null.h>
  24. #include <LayerState.h>
  25. #include <Code_LayerLock.h>
  26. #include <Code_LayerHold.h>
  27. #include <Key_LayeredKeys.h>
  28. //Matrix
  29. #include <Row.h>
  30. #include <Scanner_uC.h>
  31. #include <ScanDelay.h>
  32. // ============ SPEED CONFIGURATION ============
  33. ScanDelay scanDelay(9000);
  34. // ================== SCANNER ==================
  35. uint8_t readPins[] = {14, 15, 16};
  36. uint8_t readPinCount = sizeof(readPins)/sizeof(*readPins);
  37. Scanner_uC scanner(LOW, readPins, readPinCount);
  38. /* =================== CODES ===================
  39. The CODES section instantiates six codes, one for each item in the layout.
  40. */
  41. /* ---------------- LAYER CODE -----------------
  42. enum assigns layerId numbers to the layers.
  43. */
  44. enum layers { NORMAL, SYM, NUM };
  45. /* layerState keeps track of the active layer.
  46. */
  47. LayerState layerState;
  48. /*
  49. NORMAL=0 and FN=1. LayerState's default layerId is 0.
  50. The Code_LayerHold constructor has two parameters:
  51. 1) the layerId that will be active while the key is held down
  52. 2) a LayerState that will keep track of the active layer
  53. When l_fn is pressed, it tells layerState to change the active layer to 1.
  54. When l_fn is released, it tells layerState that layer 1 is released, and layerState restores the default layer.
  55. */
  56. Code_LayerLock l_normal(NORMAL, layerState);
  57. Code_LayerLock l_sym(SYM, layerState);
  58. Code_LayerHold l_num(NUM, layerState);
  59. // ---------------- SCAN CODES -----------------
  60. Code_Sc s_a(KEY_A);
  61. Code_Sc s_b(KEY_B);
  62. Code_Sc s_c(KEY_C);
  63. Code_Sc s_minus(KEY_MINUS);
  64. Code_Sc s_equal(KEY_EQUAL);
  65. Code_Sc s_enter(KEY_ENTER);
  66. Code_Sc s_1(KEY_1);
  67. Code_Null code_null;
  68. /* =================== KEYS ====================
  69. Here we pack Codes into keys.
  70. The Key_LayeredKeys constructor takes one array of Code pointers - one Code object per layer.
  71. The Key object names in this sketch start with a "k_" followed by row-column coordinates.
  72. */
  73. Key* const ptrsCodes_00[] = { &s_a, &s_minus, &s_1 };
  74. Key_LayeredKeys k_00(ptrsCodes_00);
  75. Key* const ptrsCodes_01[] = { &s_b, &s_equal, &s_equal };
  76. Key_LayeredKeys k_01(ptrsCodes_01);
  77. Key* const ptrsCodes_02[] = { &s_c, &l_num, &code_null };
  78. Key_LayeredKeys k_02(ptrsCodes_02);
  79. /* Key_LayeredKeys has a reference to layerState.
  80. Thus Key_LayeredKeys can call layerState to get the active layerId.
  81. */
  82. LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
  83. /* HOW LAYERED OBJECTS WORK
  84. When a Key_LayeredKeys object is pressed, it gets the active layer id from layerState.
  85. It then uses the layer id as an array index to call the Code of the active layer.
  86. The Code object then sends its scancode over USB.
  87. */
  88. /* =================== ROWS ====================
  89. Here we pack Key pointers into row objects.
  90. Codes are a kind of Key that only have one layer.
  91. So rows can contain a mix of codes and multi-layered keys.
  92. Arrays ptrsKeys_0[] and ptrsKeys_1[] contain both Code pointers and Key pointers.
  93. */
  94. Key* const ptrsKeys_0[] = { &k_00, &k_01, &k_02 };
  95. uint8_t keyCount_0 = sizeof(ptrsKeys_0)/sizeof(*ptrsKeys_0);
  96. Row row_0(scanner, 0, ptrsKeys_0, keyCount_0);
  97. Key* const ptrsKeys_1[] = { &l_normal, &l_sym, &s_enter };
  98. uint8_t keyCount_1 = sizeof(ptrsKeys_1)/sizeof(*ptrsKeys_1);
  99. Row row_1(scanner, 1, ptrsKeys_1, keyCount_1);
  100. // ################### MAIN ####################
  101. void setup()
  102. {
  103. Keyboard.begin();
  104. }
  105. void loop()
  106. {
  107. row_0.process();
  108. row_1.process();
  109. scanDelay.delay();
  110. }