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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* keybrd_5b_LED_on_IOE.ino
  2. This sketch:
  3. is a simple 1-layer keyboard with CapsLck indicator LED on I/O expander
  4. runs on two matrices of a 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. | Left | **0** | **1** | | Right | **0** | **1** |
  8. |:-----:|-------|-------|-|:-----:|-------|-------|
  9. | **1** | 1 | 2 | | **1** | 3 |CapsLck|
  10. | **0** | a | b | | **0** | c | d |
  11. */
  12. // ################## GLOBAL ###################
  13. // ================= INCLUDES ==================
  14. #include <ScanDelay.h>
  15. #include <Code_LEDLock.h>
  16. #include <Code_Sc.h>
  17. #include <Row.h>
  18. //left matrix
  19. #include <Scanner_uC.h>
  20. //right matrix
  21. #include <PortIOE.h>
  22. #include <PortWrite_MCP23S17.h>
  23. #include <PortRead_MCP23S17.h>
  24. #include <Scanner_IOE.h>
  25. #include <LED_IOE.h>
  26. // ============ SPEED CONFIGURATION ============
  27. ScanDelay scanDelay(9000);
  28. // ================ LEFT SCANNER ===============
  29. uint8_t readPins[] = {14, 15};
  30. const uint8_t READPIN_COUNT = sizeof(readPins)/sizeof(*readPins);
  31. Scanner_uC scanner_L(LOW, readPins, READPIN_COUNT);
  32. // =============== RIGHT SCANNER ===============
  33. const uint8_t PortIOE::DEVICE_ADDR = 0x20; //MCP23S17 address with all 3 ADDR pins are grounded
  34. PortIOE port_A(0);
  35. PortRead_MCP23S17 portRead(port_A, 1<<0 | 1<<1 );
  36. PortWrite_MCP23S17 portWriteA(port_A); //for LED
  37. //todo portWriteA(port_A) instantiation would not be needed if PortRead_MCP23S17 had write()
  38. // consider moving PortWrite_MCP23S17::write to Port_MCP23S17 (parent)
  39. // and passing portRead to LED_IOE
  40. // same for PCA9655E
  41. PortIOE port_B(1);
  42. PortWrite_MCP23S17 portWrite(port_B);
  43. Scanner_IOE scanner_R(LOW, portWrite, portRead);
  44. // ================ RIGHT LEDs =================
  45. LED_IOE LED_CapsLck(portWriteA, 1<<6); //tested LED on port A (read)
  46. //LED_IOE LED_CapsLck(portWrite, 1<<6);//tested LED on port B (write)
  47. // =================== CODES ===================
  48. Code_Sc s_a(KEY_A);
  49. Code_Sc s_b(KEY_B);
  50. Code_Sc s_c(KEY_C);
  51. Code_Sc s_d(KEY_D);
  52. Code_Sc s_1(KEY_1);
  53. Code_Sc s_2(KEY_2);
  54. Code_Sc s_3(KEY_3);
  55. Code_LEDLock o_capsLock(KEY_CAPS_LOCK, LED_CapsLck);
  56. // =================== ROWS ====================
  57. // ---------------- LEFT ROWS ------------------
  58. Key* ptrsKeys_L0[] = { &s_1, &s_2 };
  59. const uint8_t KEY_COUNT_L0 = sizeof(ptrsKeys_L0)/sizeof(*ptrsKeys_L0);
  60. Row row_L0(scanner_L, 0, ptrsKeys_L0, KEY_COUNT_L0);
  61. Key* ptrsKeys_L1[] = { &s_a, &s_b };
  62. const uint8_t KEY_COUNT_L1 = sizeof(ptrsKeys_L1)/sizeof(*ptrsKeys_L1);
  63. Row row_L1(scanner_L, 1, ptrsKeys_L1, KEY_COUNT_L1);
  64. // ---------------- RIGHT ROWS -----------------
  65. Key* ptrsKeys_R0[] = { &s_3, &o_capsLock };
  66. const uint8_t KEY_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  67. Row row_R0(scanner_R, 1<<0, ptrsKeys_R0, KEY_COUNT_R0);
  68. Key* ptrsKeys_R1[] = { &s_c, &s_d };
  69. const uint8_t KEY_COUNT_R1 = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
  70. Row row_R1(scanner_R, 1<<1, ptrsKeys_R1, KEY_COUNT_R1);
  71. // ################### MAIN ####################
  72. void setup()
  73. {
  74. Keyboard.begin();
  75. scanner_R.begin();
  76. }
  77. void loop()
  78. {
  79. //left matrix
  80. row_L0.process();
  81. row_L1.process();
  82. //right matrix
  83. row_R0.process();
  84. row_R1.process();
  85. scanDelay.delay();
  86. //debug.print_scans_per_second();
  87. //debug.print_microseconds_per_scan();
  88. }