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_3b_multi-layerLock.ino 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* keybrd_3b_multi-layerLock.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** |
  6. |:------:|:-----:|:-----:|
  7. | **0** | a - | b = |
  8. | **1** | Alpha | Sym |
  9. Pressing the "Alpha" layer key locks the Alpha layer.
  10. Letters 'a' 'b' are on the Alpha layer.
  11. Pressing the "Sym" layer key locks the Sym layer.
  12. Symbols '-' '=' are on the Sym layer.
  13. */
  14. // ################## GLOBAL ###################
  15. // ================= INCLUDES ==================
  16. //Keys
  17. #include <Code_Sc.h>
  18. #include <LayerState.h>
  19. #include <Code_LayerLock.h>
  20. #include <Key_LayeredKeys.h>
  21. //Matrix
  22. #include <Row.h>
  23. #include <Scanner_uC.h>
  24. #include <ScanDelay.h>
  25. // ============ SPEED CONFIGURATION ============
  26. ScanDelay scanDelay(9000);
  27. // ================== SCANNER ==================
  28. uint8_t readPins[] = {14, 15};
  29. uint8_t readPinCount = sizeof(readPins)/sizeof(*readPins);
  30. Scanner_uC scanner(LOW, readPins, readPinCount);
  31. // =================== CODES ===================
  32. // ---------------- LAYER CODE -----------------
  33. enum layerIds { ALPHA, SYM };
  34. LayerState layerState;
  35. /*
  36. Code_LayerLock constructor parameters are: layerId, LayerState.
  37. layerId becomes the active layer when the key is pressed.
  38. LayerState keeps track of the active layer.
  39. In this example, when l_normal is pressed, ALPHA becomes the active layer.
  40. When l_sym is pressed, SYM becomes the active layer.
  41. */
  42. Code_LayerLock l_normal(ALPHA, layerState);
  43. Code_LayerLock l_sym(SYM, layerState);
  44. // ----------------- SCANCODES -----------------
  45. Code_Sc s_a(KEY_A);
  46. Code_Sc s_b(KEY_B);
  47. Code_Sc s_minus(KEY_MINUS);
  48. Code_Sc s_equal(KEY_EQUAL);
  49. // =================== KEYS ====================
  50. Key* const ptrsKeys_00[] = { &s_a, &s_minus };
  51. Key_LayeredKeys k_00(ptrsKeys_00);
  52. Key* const ptrsKeys_01[] = { &s_b, &s_equal };
  53. Key_LayeredKeys k_01(ptrsKeys_01);
  54. LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
  55. // =================== ROWS ====================
  56. Key* const ptrsKeys_0[] = { &k_00, &k_01 };
  57. uint8_t keyCount_0 = sizeof(ptrsKeys_0)/sizeof(*ptrsKeys_0);
  58. Row row_0(scanner, 0, ptrsKeys_0, keyCount_0);
  59. Key* const ptrsKeys_1[] = { &l_normal, &l_sym };
  60. uint8_t keyCount_1 = sizeof(ptrsKeys_1)/sizeof(*ptrsKeys_1);
  61. Row row_1(scanner, 1, ptrsKeys_1, keyCount_1);
  62. // ################### MAIN ####################
  63. void setup()
  64. {
  65. }
  66. void loop()
  67. {
  68. row_0.process();
  69. row_1.process();
  70. scanDelay.delay();
  71. }