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_works1.no 3.5KB

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