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_3f_autoShift.ino 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* keybrd_3f_autoShift.ino
  2. This sketch:
  3. is a simple 2-layer keyboard with AutoShift
  4. runs on the first two rows and columns of a breadboard keyboard
  5. | Layout | **0** | **1** |
  6. |:------:|-------|-------|
  7. | **0** | a ! | b @ |
  8. | **1** | fn | shift |
  9. The layered keys in row 0 have two layers; one character for each layer.
  10. Letters 'a' and 'b' are on the normal layer. Symbols '!' and '@' are one the fn layer.
  11. Holding the fn key down makes it the active layer. Releasing the fn key restores the normal layer.
  12. */
  13. // ################## GLOBAL ###################
  14. // ================= INCLUDES ==================
  15. //Keys
  16. #include <Code_Sc.h>
  17. #include <Code_ScS.h>
  18. #include <Code_Shift.h>
  19. #include <LayerState.h>
  20. #include <Code_LayerHold.h>
  21. #include <Key_LayeredKeys.h>
  22. //Matrix
  23. #include <Row.h>
  24. #include <Scanner_uC.h>
  25. #include <ScanDelay.h>
  26. // ============ SPEED CONFIGURATION ============
  27. ScanDelay scanDelay(9000);
  28. // ================== SCANNER ==================
  29. uint8_t readPins[] = {14, 15};
  30. uint8_t readPinCount = sizeof(readPins)/sizeof(*readPins);
  31. Scanner_uC scanner(LOW, readPins, readPinCount);
  32. // =================== CODES ===================
  33. // ---------------- LAYER CODE -----------------
  34. enum layerIds { NORMAL, FN };
  35. LayerState layerState;
  36. Code_LayerHold l_fn(FN, layerState);
  37. /* ----------------- SCANCODES -----------------
  38. The "Sc" in Code_Sc means "scancode".
  39. When a Code_Sc is pressed, it sends its scancode.
  40. */
  41. Code_Sc s_a(KEY_A);
  42. Code_Sc s_b(KEY_B);
  43. /* The "ScS" in Code_ScS means "scancode shifted".
  44. When Code_ScS is pressed, it calls Code_AutoShift before sending its scancode.
  45. */
  46. Code_ScS s_exclamation(KEY_1);
  47. Code_ScS s_at(KEY_2);
  48. // ----------------- SHIFT CODE ----------------
  49. /*
  50. The Code_Shift constructor takes one shift scancode.
  51. */
  52. Code_Shift s_shift(MODIFIERKEY_LEFT_SHIFT);
  53. /*
  54. Code_Shift pointers are placed in an array because most keyboards have a left and right shift.
  55. This sketch only has one shift code.
  56. */
  57. Code_Shift* const ptrsS[] = { &s_shift };
  58. Code_Shift* const* const Code_AutoShift::ptrsShifts = ptrsS;
  59. const uint8_t Code_AutoShift::shiftCount = sizeof(ptrsS)/sizeof(*ptrsS);
  60. /*
  61. HOW SHIFT WORKS
  62. When a shift key is pressed, a standard keyboard driver will temporarily modify the action of other scancodes.
  63. KEY_1 writes '1'
  64. MODIFIERKEY_LEFT_SHIFT + KEY_1 writes '!'
  65. KEY_2 writes '2'
  66. MODIFIERKEY_LEFT_SHIFT + KEY_2 writes '@'
  67. HOW AUTOSHIFT WORKS
  68. Code_ScS takes care of the MODIFIERKEY_LEFT_SHIFT automatically
  69. When the user presses '!' or '@' on the fn layer:
  70. Code_AutoShift checks the position of each shift key
  71. Code_ScS sends MODIFIERKEY_LEFT_SHIFT scancode if needed
  72. Code_ScS sends its scancode
  73. */
  74. // =================== KEYS ====================
  75. Key* const ptrsKeys_00[] = { &s_a, &s_exclamation };
  76. Key_LayeredKeys k_00(ptrsKeys_00);
  77. Key* const ptrsKeys_01[] = { &s_b, &s_at };
  78. Key_LayeredKeys k_01(ptrsKeys_01);
  79. LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
  80. // =================== ROWS ====================
  81. Key* const ptrsKeys_0[] = { &k_00, &k_01 };
  82. uint8_t keyCount_0 = sizeof(ptrsKeys_0)/sizeof(*ptrsKeys_0);
  83. Row row_0(scanner, 0, ptrsKeys_0, keyCount_0);
  84. Key* const ptrsKeys_1[] = { &l_fn, &s_shift };
  85. uint8_t keyCount_1 = sizeof(ptrsKeys_1)/sizeof(*ptrsKeys_1);
  86. Row row_1(scanner, 1, ptrsKeys_1, keyCount_1);
  87. // ################### MAIN ####################
  88. void setup()
  89. {
  90. }
  91. void loop()
  92. {
  93. row_0.process();
  94. row_1.process();
  95. scanDelay.delay();
  96. }