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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <PortMCP23S17.h>
  23. #include <Scanner_IOE.h>
  24. #include <LED_IOE.h>
  25. // ============ SPEED CONFIGURATION ============
  26. ScanDelay scanDelay(9000);
  27. // ================ LEFT SCANNER ===============
  28. uint8_t readPins[] = {14, 15};
  29. const uint8_t READPIN_COUNT = sizeof(readPins)/sizeof(*readPins);
  30. Scanner_uC scanner_L(LOW, readPins, READPIN_COUNT);
  31. // =============== RIGHT SCANNER ===============
  32. const uint8_t PortIOE::DEVICE_ADDR = 0x20; //MCP23S17 address with all 3 ADDR pins are grounded
  33. PortIOE port_A(0);
  34. PortMCP23S17 portRead(port_A, 1<<0 | 1<<1 );
  35. PortIOE port_B(1);
  36. PortMCP23S17 portWrite(port_B, 0);
  37. Scanner_IOE scanner_R(LOW, portWrite, portRead);
  38. // ================ RIGHT LEDs =================
  39. LED_IOE LED_CapsLck(portRead, 1<<6); //tested LED on port A (read)
  40. //LED_IOE LED_CapsLck(portWrite, 1<<6);//tested LED on port B (write)
  41. // =================== CODES ===================
  42. Code_Sc s_a(KEY_A);
  43. Code_Sc s_b(KEY_B);
  44. Code_Sc s_c(KEY_C);
  45. Code_Sc s_d(KEY_D);
  46. Code_Sc s_1(KEY_1);
  47. Code_Sc s_2(KEY_2);
  48. Code_Sc s_3(KEY_3);
  49. Code_LEDLock o_capsLock(KEY_CAPS_LOCK, LED_CapsLck);
  50. // =================== ROWS ====================
  51. // ---------------- LEFT ROWS ------------------
  52. Key* ptrsKeys_L0[] = { &s_1, &s_2 };
  53. const uint8_t KEY_COUNT_L0 = sizeof(ptrsKeys_L0)/sizeof(*ptrsKeys_L0);
  54. Row row_L0(scanner_L, 0, ptrsKeys_L0, KEY_COUNT_L0);
  55. Key* ptrsKeys_L1[] = { &s_a, &s_b };
  56. const uint8_t KEY_COUNT_L1 = sizeof(ptrsKeys_L1)/sizeof(*ptrsKeys_L1);
  57. Row row_L1(scanner_L, 1, ptrsKeys_L1, KEY_COUNT_L1);
  58. // ---------------- RIGHT ROWS -----------------
  59. Key* ptrsKeys_R0[] = { &s_3, &o_capsLock };
  60. const uint8_t KEY_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  61. Row row_R0(scanner_R, 1<<0, ptrsKeys_R0, KEY_COUNT_R0);
  62. Key* ptrsKeys_R1[] = { &s_c, &s_d };
  63. const uint8_t KEY_COUNT_R1 = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
  64. Row row_R1(scanner_R, 1<<1, ptrsKeys_R1, KEY_COUNT_R1);
  65. // ################### MAIN ####################
  66. void setup()
  67. {
  68. Keyboard.begin();
  69. delay(7000);
  70. scanner_R.begin();
  71. }
  72. void loop()
  73. {
  74. //left matrix
  75. row_L0.process();
  76. row_L1.process();
  77. //right matrix
  78. row_R0.process();
  79. row_R1.process();
  80. scanDelay.delay();
  81. //debug.print_scans_per_second();
  82. //debug.print_microseconds_per_scan();
  83. }