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_5b_LED_on_IOE.ino 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* keybrd_5b_LED_on_IOE.ino
  2. This sketch:
  3. is a simple 1-layer keyboard with indicator LED on controller and 2 LEDs on I/O expander
  4. runs on a two-matrix breadboard keyboard
  5. modified keybrd_4c_split_keyboard_with_IOE.ino by adding LED_capsLck
  6. This layout table shows left and right matrices:
  7. Controller I/O expander
  8. | Left | **0** | **1** | | Right | **0** | **1** |
  9. |:-----:|-------|-------|-|:-----:|-------|-------|
  10. | **0** |CapsLck| a 1 | | **1** | b 2 | c 3 |
  11. | **1** | fn | x = | | **0** | y - | z / |
  12. */
  13. // ################## GLOBAL ###################
  14. // ================= INCLUDES ==================
  15. #include <ScanDelay.h>
  16. #include <LayerState_LED.h>
  17. #include <Code_LayerHold.h>
  18. #include <Code_LEDLock.h>
  19. #include <Key_LayeredKeys.h>
  20. #include <Code_Sc.h>
  21. #include <Row.h>
  22. //left matrix
  23. #include <Scanner_uC.h>
  24. #include <LED_uC.h>
  25. //right matrix
  26. #include <Port_MCP23S17.h>
  27. #include <Scanner_IOE.h>
  28. #include <LED_Port.h>
  29. // ============ SPEED CONFIGURATION ============
  30. ScanDelay scanDelay(9000);
  31. // ==================== ICs ====================
  32. // ---------------- LEFT SCANNER ---------------
  33. uint8_t readPins[] = {14, 15};
  34. const uint8_t readPinCount = sizeof(readPins)/sizeof(*readPins);
  35. Scanner_uC scanner_L(LOW, readPins, readPinCount);
  36. // ----------------- LEFT LEDs -----------------
  37. LED_uC LED_capsLck(21);
  38. // --------------- RIGHT SCANNER ---------------
  39. const uint8_t IOE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded
  40. Port_MCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 ); //for read
  41. Port_MCP23S17 portB(IOE_ADDR, 1, 0); //for strobe
  42. Scanner_IOE scanner_R(LOW, portB, portA);
  43. /* ---------------- RIGHT LEDs -----------------
  44. The LED_Port constructor parameters are a port and pin number that is connected to an LED.
  45. */
  46. LED_Port LED_normal(portA, 1<<5);
  47. LED_Port LED_fn(portB, 1<<4);
  48. // =================== CODES ===================
  49. // ---------------- LAYER CODE -----------------
  50. enum layerIds { NORMAL, FN };
  51. LEDInterface* prtsLayerLEDs[] = { &LED_normal, &LED_fn }; //array index matches enum layerIds
  52. LayerState_LED layerState(prtsLayerLEDs);
  53. Code_LayerHold l_fn(FN, layerState);
  54. // ---------------- SCAN CODES -----------------
  55. Code_Sc s_a(KEY_A);
  56. Code_Sc s_b(KEY_B);
  57. Code_Sc s_c(KEY_C);
  58. Code_Sc s_x(KEY_X);
  59. Code_Sc s_y(KEY_Y);
  60. Code_Sc s_z(KEY_Z);
  61. Code_Sc s_1(KEY_1);
  62. Code_Sc s_2(KEY_2);
  63. Code_Sc s_3(KEY_3);
  64. Code_Sc s_minus(KEY_MINUS);
  65. Code_Sc s_equal(KEY_EQUAL);
  66. Code_Sc s_slash(KEY_SLASH);
  67. Code_LEDLock o_capsLock(KEY_CAPS_LOCK, LED_capsLck);
  68. // =================== KEYS ====================
  69. //row0
  70. Key* const ptrsKeys_01[] = { &s_a, &s_1 };
  71. Key_LayeredKeys k_01(ptrsKeys_01);
  72. Key* const ptrsKeys_02[] = { &s_b, &s_2 };
  73. Key_LayeredKeys k_02(ptrsKeys_02);
  74. Key* const ptrsKeys_03[] = { &s_c, &s_3 };
  75. Key_LayeredKeys k_03(ptrsKeys_03);
  76. //row1
  77. Key* const ptrsKeys_11[] = { &s_x, &s_equal };
  78. Key_LayeredKeys k_11(ptrsKeys_11);
  79. Key* const ptrsKeys_12[] = { &s_y, &s_minus };
  80. Key_LayeredKeys k_12(ptrsKeys_12);
  81. Key* const ptrsKeys_13[] = { &s_z, &s_slash };
  82. Key_LayeredKeys k_13(ptrsKeys_13);
  83. LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
  84. // =================== ROWS ====================
  85. // ---------------- LEFT ROWS ------------------
  86. Key* ptrsKeys_L0[] = { &o_capsLock, &k_01 };
  87. const uint8_t KEY_COUNT_L0 = sizeof(ptrsKeys_L0)/sizeof(*ptrsKeys_L0);
  88. Row row_L0(scanner_L, 0, ptrsKeys_L0, KEY_COUNT_L0);
  89. Key* ptrsKeys_L1[] = { &l_fn, &k_11 };
  90. const uint8_t KEY_COUNT_L1 = sizeof(ptrsKeys_L1)/sizeof(*ptrsKeys_L1);
  91. Row row_L1(scanner_L, 1, ptrsKeys_L1, KEY_COUNT_L1);
  92. // ---------------- RIGHT ROWS -----------------
  93. Key* ptrsKeys_R0[] = { &k_02, &k_03};
  94. const uint8_t KEY_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  95. Row row_R0(scanner_R, 1<<0, ptrsKeys_R0, KEY_COUNT_R0);
  96. Key* ptrsKeys_R1[] = { &k_12, &k_13 };
  97. const uint8_t KEY_COUNT_R1 = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
  98. Row row_R1(scanner_R, 1<<1, ptrsKeys_R1, KEY_COUNT_R1);
  99. /* ################### MAIN ####################
  100. LayerState_LED::begin() is called after Scanner_IOE::begin()
  101. so that scanner's ports can turn on LayerState_LED's default-layer LED.
  102. */
  103. void setup()
  104. {
  105. Keyboard.begin();
  106. scanner_R.begin();
  107. layerState.begin(); //call LayerState_LED::begin() after Scanner_IOE::begin()
  108. }
  109. void loop()
  110. {
  111. //left matrix
  112. row_L0.process();
  113. row_L1.process();
  114. //right matrix
  115. row_R0.process();
  116. row_R1.process();
  117. scanDelay.delay();
  118. //debug.printScansPerSecond();
  119. //debug.printMicrosecondsPerScan();
  120. }