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_shift_reg.ino 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* keybrd_shift_reg.ino
  2. this works on Teensy LC 1*bb, active low and active high
  3. | Layout | **0** | **1** |
  4. |:------:|-------|-------|
  5. | **0** | a | b |
  6. | **1** | c | d |
  7. */
  8. // ################## GLOBAL ###################
  9. // ================= INCLUDES ==================
  10. #include <Debug.h>
  11. //IOE Ports
  12. #include "IOExpanderPort.h"
  13. #include <RowPort_MCP23018.h>
  14. #include <ColPort_MCP23018.h>
  15. //Codes
  16. #include <Code_Sc.h>
  17. //Matrix
  18. #include <Row_uC.h>
  19. #include <SPI.h>
  20. #include <Row_ShiftRegisters.h>
  21. // =============== CONFIGURATION ===============
  22. const unsigned int RowBase::DELAY_MICROSECONDS = 500; //500
  23. //activeLow has diode cathode (band) on row
  24. //activeHigh has diode cathode (band) on col, and pull down resistors on cols
  25. //0=active low, 1= active high
  26. const bool RowScanner_PinsArray::ACTIVE_HIGH = 0;
  27. Debug debug;
  28. // ================= LEFT PINS =================
  29. uint8_t readPins[] = {14, 15};
  30. uint8_t READ_PIN_COUNT = sizeof(readPins)/sizeof(*readPins);
  31. // =================== CODES ===================
  32. Code_Sc s_a(KEY_A);
  33. Code_Sc s_b(KEY_B);
  34. Code_Sc s_c(KEY_C);
  35. Code_Sc s_d(KEY_D);
  36. Code_Sc s_e(KEY_E);
  37. Code_Sc s_f(KEY_F);
  38. Code_Sc s_g(KEY_G);
  39. Code_Sc s_h(KEY_H);
  40. Code_Sc s_i(KEY_I);
  41. Code_Sc s_0(KEY_0);
  42. Code_Sc s_1(KEY_1);
  43. Code_Sc s_2(KEY_2);
  44. Code_Sc s_3(KEY_3);
  45. Code_Sc s_4(KEY_4);
  46. Code_Sc s_5(KEY_5);
  47. Code_Sc s_6(KEY_6);
  48. Code_Sc s_7(KEY_7);
  49. Code_Sc s_8(KEY_8);
  50. Code_Sc s_z(KEY_Z);
  51. // ================= LEFT ROWS =================
  52. Key* ptrsKeys_L0[] = { &s_a, &s_b };
  53. Row_uC row_L0(0, readPins, READ_PIN_COUNT, ptrsKeys_L0);
  54. Key* ptrsKeys_L1[] = { &s_c, &s_d };
  55. Row_uC row_L1(1, readPins, READ_PIN_COUNT, ptrsKeys_L1);
  56. // ================= RIGHT ROWS ================
  57. //typedef should be large in /home/wolfv/Documents/Arduino/keybrd_proj/keybrd/src/config_keybrd.h
  58. //Row_ShiftRegisters(STROBE_PIN, SHIFT_LOAD, ptrsKeys[], KEY_COUNT)
  59. //the s_z are place holders and should not print
  60. /*
  61. //BYTE_COUNT 1, prints 0 1
  62. Key* ptrsKeys_R0[] = { &s_0, &s_a, &s_b, &s_c, &s_1, &s_d, &s_e, &s_f };
  63. const uint8_t KEY_R0_COUNT = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  64. Row_ShiftRegisters row_R0(8, 10, ptrsKeys_R0, KEY_R0_COUNT);
  65. */
  66. /*
  67. //prints 0 1 2
  68. Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z,
  69. &s_2, &s_z, &s_z, &s_z };
  70. const uint8_t KEY_R0_COUNT = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  71. Row_ShiftRegisters row_R0(8, 10, ptrsKeys_R0, KEY_R0_COUNT);
  72. */
  73. /*
  74. //prints 0 1 2 3
  75. Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z,
  76. &s_2, &s_z, &s_z, &s_z, &s_3, &s_z, &s_z, &s_z };
  77. const uint8_t KEY_R0_COUNT = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  78. Row_ShiftRegisters row_R0(8, 10, ptrsKeys_R0, KEY_R0_COUNT);
  79. */
  80. /*
  81. //prints 0 1 2 3 4 5
  82. Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z,
  83. &s_2, &s_z, &s_z, &s_z, &s_3, &s_z, &s_z, &s_z,
  84. &s_4, &s_z, &s_z, &s_z, &s_5, &s_z, &s_z, &s_z };
  85. const uint8_t KEY_R0_COUNT = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  86. Row_ShiftRegisters row_R0(8, 10, ptrsKeys_R0, KEY_R0_COUNT);
  87. */
  88. //prints 0 1 2 3 4 5 6 7 8
  89. Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z,
  90. &s_2, &s_z, &s_z, &s_z, &s_3, &s_z, &s_z, &s_z,
  91. &s_4, &s_z, &s_z, &s_z, &s_5, &s_z, &s_z, &s_z,
  92. &s_6, &s_z, &s_z, &s_z, &s_7, &s_z, &s_8 }; //31-key limit because endRow
  93. const uint8_t KEY_R0_COUNT = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  94. Row_ShiftRegisters row_R0(8, 10, ptrsKeys_R0, KEY_R0_COUNT);
  95. //unresponsive
  96. Key* ptrsKeys_R1[] = { &s_a, &s_z, &s_z, &s_z, &s_b, &s_z, &s_z, &s_z,
  97. &s_c, &s_z, &s_z, &s_z, &s_d, &s_z, &s_z, &s_z,
  98. &s_e, &s_z, &s_z, &s_z, &s_f, &s_z, &s_z, &s_z,
  99. &s_g, &s_z, &s_z, &s_z, &s_h, &s_z, &s_i }; //31-key limit because endRow
  100. const uint8_t KEY_R1_COUNT = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
  101. Row_ShiftRegisters row_R1(9, 10, ptrsKeys_R1, KEY_R1_COUNT);
  102. const uint8_t LED_PIN = 16; //indicates wait
  103. //sometimes OS takes 6 seconds to recongnize keyboard, LED blinks from the begining
  104. void wait()
  105. {
  106. for (uint8_t count = 0; count < 6; count++)
  107. {
  108. //print count
  109. Keyboard.print(count);
  110. Keyboard.print(F(" "));
  111. //blink LED
  112. digitalWrite(LED_PIN, HIGH);
  113. delay(900);
  114. digitalWrite(LED_PIN, LOW);
  115. delay(100);
  116. }
  117. }
  118. // ################### MAIN ####################
  119. void setup()
  120. {
  121. pinMode (LED_PIN, OUTPUT);
  122. Keyboard.begin();
  123. SPI.begin();
  124. wait();
  125. row_R0.begin();
  126. row_R1.begin();
  127. Keyboard.print(F("keybrd_shift_reg.ino "));
  128. debug.print_free_RAM();
  129. }
  130. void loop()
  131. {
  132. row_L0.process();
  133. row_L1.process();
  134. row_R0.process();
  135. row_R1.process();
  136. //delay(100);
  137. //Keyboard.println("");
  138. //debug.print_microseconds_per_scan();
  139. }