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.6KB

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. const uint8_t slaveSelect = 10; //Arduino-pin number connected to MCP23S17 CS or SS
  41. Port_MCP23S17 portA(slaveSelect , IOE_ADDR, 0, 1<<0 | 1<<1 ); //for read
  42. Port_MCP23S17 portB(slaveSelect , IOE_ADDR, 1, 0); //for strobe
  43. Scanner_IOE scanner_R(LOW, portB, portA);
  44. /* ---------------- RIGHT LEDs -----------------
  45. The LED_Port constructor parameters are a port and pin number that is connected to an LED.
  46. */
  47. LED_Port LED_normal(portA, 1<<5);
  48. LED_Port LED_fn(portB, 1<<4);
  49. // =================== CODES ===================
  50. // ---------------- LAYER CODES ----------------
  51. enum layerIds { NORMAL, FN };
  52. LEDInterface* prtsLayerLEDs[] = { &LED_normal, &LED_fn }; //array index matches enum layerIds
  53. LayerState_LED layerState(prtsLayerLEDs);
  54. Code_LayerHold l_fn(FN, layerState);
  55. // ----------------- SCANCODES -----------------
  56. Code_Sc s_a(KEY_A);
  57. Code_Sc s_b(KEY_B);
  58. Code_Sc s_c(KEY_C);
  59. Code_Sc s_x(KEY_X);
  60. Code_Sc s_y(KEY_Y);
  61. Code_Sc s_z(KEY_Z);
  62. Code_Sc s_1(KEY_1);
  63. Code_Sc s_2(KEY_2);
  64. Code_Sc s_3(KEY_3);
  65. Code_Sc s_minus(KEY_MINUS);
  66. Code_Sc s_equal(KEY_EQUAL);
  67. Code_Sc s_slash(KEY_SLASH);
  68. Code_LEDLock o_capsLock(KEY_CAPS_LOCK, LED_capsLck);
  69. // =================== KEYS ====================
  70. //row0
  71. Key* const ptrsKeys_01[] = { &s_a, &s_1 };
  72. Key_LayeredKeys k_01(ptrsKeys_01);
  73. Key* const ptrsKeys_02[] = { &s_b, &s_2 };
  74. Key_LayeredKeys k_02(ptrsKeys_02);
  75. Key* const ptrsKeys_03[] = { &s_c, &s_3 };
  76. Key_LayeredKeys k_03(ptrsKeys_03);
  77. //row1
  78. Key* const ptrsKeys_11[] = { &s_x, &s_equal };
  79. Key_LayeredKeys k_11(ptrsKeys_11);
  80. Key* const ptrsKeys_12[] = { &s_y, &s_minus };
  81. Key_LayeredKeys k_12(ptrsKeys_12);
  82. Key* const ptrsKeys_13[] = { &s_z, &s_slash };
  83. Key_LayeredKeys k_13(ptrsKeys_13);
  84. LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
  85. // =================== ROWS ====================
  86. // ---------------- LEFT ROWS ------------------
  87. Key* ptrsKeys_L0[] = { &o_capsLock, &k_01 };
  88. const uint8_t KEY_COUNT_L0 = sizeof(ptrsKeys_L0)/sizeof(*ptrsKeys_L0);
  89. Row row_L0(scanner_L, 0, ptrsKeys_L0, KEY_COUNT_L0);
  90. Key* ptrsKeys_L1[] = { &l_fn, &k_11 };
  91. const uint8_t KEY_COUNT_L1 = sizeof(ptrsKeys_L1)/sizeof(*ptrsKeys_L1);
  92. Row row_L1(scanner_L, 1, ptrsKeys_L1, KEY_COUNT_L1);
  93. // ---------------- RIGHT ROWS -----------------
  94. Key* ptrsKeys_R0[] = { &k_02, &k_03};
  95. const uint8_t KEY_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  96. Row row_R0(scanner_R, 1<<0, ptrsKeys_R0, KEY_COUNT_R0);
  97. Key* ptrsKeys_R1[] = { &k_12, &k_13 };
  98. const uint8_t KEY_COUNT_R1 = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
  99. Row row_R1(scanner_R, 1<<1, ptrsKeys_R1, KEY_COUNT_R1);
  100. /* ################### MAIN ####################
  101. LayerState_LED::begin() is called after Scanner_IOE::begin()
  102. so that scanner's ports can turn on LayerState_LED's default-layer LED.
  103. */
  104. void setup()
  105. {
  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. }