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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* keybrd_3c_sublayerNull.ino
  2. This sketch:
  3. is firmware for layout with 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** | Alpha | Sym | Enter |
  9. */
  10. // ################## GLOBAL ###################
  11. // ================= INCLUDES ==================
  12. //Keys
  13. #include <Code_Sc.h>
  14. #include <Code_Null.h>
  15. #include <LayerState.h>
  16. #include <Code_LayerLock.h>
  17. #include <Code_LayerHold.h>
  18. #include <Key_LayeredKeys.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. One LayerState object manages all 3 layers.
  32. */
  33. enum layerIds { ALPHA, SYM, NUM };
  34. LayerState layerState;
  35. Code_LayerLock l_normal(ALPHA, layerState);
  36. Code_LayerLock l_sym(SYM, layerState);
  37. Code_LayerHold l_num(NUM, layerState);
  38. LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
  39. // ---------------- SCAN CODES -----------------
  40. Code_Sc s_a(KEY_A);
  41. Code_Sc s_b(KEY_B);
  42. Code_Sc s_c(KEY_C);
  43. Code_Sc s_minus(KEY_MINUS);
  44. Code_Sc s_equal(KEY_EQUAL);
  45. Code_Sc s_enter(KEY_ENTER);
  46. Code_Sc s_1(KEY_1);
  47. Code_Null code_null;
  48. /* =================== KEYS ====================
  49. When a Key_LayeredKeys is pressed, layerState returns the active layerId,
  50. which could be any of the layerIds in l_normal, l_sym, l_num.
  51. The layout has one key with 3 layers, and two keys with 2 layers.
  52. But the layer scheme has 3 layers for all three keys.
  53. The extra layers are filled with duplicate codes and null codes.
  54. */
  55. Key* const ptrsKeys_00[] = { &s_a, &s_minus, &s_1 };
  56. Key_LayeredKeys k_00(ptrsKeys_00);
  57. /*
  58. s_equal is duplicated in layer 2.
  59. */
  60. Key* const ptrsKeys_01[] = { &s_b, &s_equal, &s_equal };
  61. Key_LayeredKeys k_01(ptrsKeys_01);
  62. /*
  63. code_null occupies layer 2. Class Code_Null doesn't do anything. It is useful for blank codes.
  64. Remember to fill all layers with codes.
  65. If the code_null were omitted from the array, dereferencing ptrsKeys_02[2] could cause a crash.
  66. */
  67. Key* const ptrsKeys_02[] = { &s_c, &l_num, &code_null };
  68. Key_LayeredKeys k_02(ptrsKeys_02);
  69. // =================== ROWS ====================
  70. Key* const ptrsKeys_0[] = { &k_00, &k_01, &k_02 };
  71. uint8_t keyCount_0 = sizeof(ptrsKeys_0)/sizeof(*ptrsKeys_0);
  72. Row row_0(scanner, 0, ptrsKeys_0, keyCount_0);
  73. Key* const ptrsKeys_1[] = { &l_normal, &l_sym, &s_enter };
  74. uint8_t keyCount_1 = sizeof(ptrsKeys_1)/sizeof(*ptrsKeys_1);
  75. Row row_1(scanner, 1, ptrsKeys_1, keyCount_1);
  76. // ################### MAIN ####################
  77. void setup()
  78. {
  79. Keyboard.begin();
  80. }
  81. void loop()
  82. {
  83. row_0.process();
  84. row_1.process();
  85. scanDelay.delay();
  86. }