Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. /*
  2. * Toshiba T1000 Keyboard interpreter
  3. *
  4. * Converts signals from a T1000 keyboard's key matrix to a stndard USB keyboard when using a Teensy LC.
  5. *
  6. * 2017 Chad Boughton
  7. */
  8.  
  9. #include <Keypad.h>
  10.  
  11. const byte ROWS = 5;
  12. const byte COLS = 8;
  13. char keys[ROWS][COLS] = {
  14. {KEY_1,KEY_2,KEY_3,KEY_4,KEY_5,KEY_6,KEY_7,KEY_8},
  15. {KEY_9,KEY_0,KEY_A,KEY_B,KEY_C,KEY_D,KEY_E,KEY_F},
  16. {KEY_G,KEY_H,KEY_I,KEY_J,KEY_K,KEY_L,KEY_M,KEY_N},
  17. {KEY_O,KEY_P,KEY_Q,KEY_R,KEY_S,KEY_T,KEY_U,KEY_V},
  18. {KEY_W,KEY_X,KEY_Y,KEY_Z,KEY_ENTER,KEY_TILDE,KEY_DELETE,KEY_BACKSPACE}
  19. };
  20. byte rowPins[ROWS] = {1,2,3,4,5}; //connect to the row pinouts of the keypad
  21. byte colPins[COLS] = {6,7,8,9,10,11,12,13}; //connect to the column pinouts of the keypad
  22.  
  23. Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  24.  
  25. unsigned long loopCount;
  26. unsigned long startTime;
  27. String msg;
  28. int x = 0;
  29.  
  30. void setup() {
  31. Serial.begin(9600);
  32. loopCount = 0;
  33. startTime = millis();
  34. msg = "";
  35. }
  36.  
  37.  
  38. void loop() {
  39. loopCount++;
  40. //char key = kpd.getKey();
  41. if ( (millis()-startTime)>5000 ) {
  42. //Serial.print("Average loops per second = ");
  43. //Serial.println(loopCount/5);
  44. startTime = millis();
  45. loopCount = 0;
  46. }
  47.  
  48.  
  49. // Fills kpd.key[ ] array with up-to 10 active keys.
  50. // Returns true if there are ANY active keys.
  51. if (kpd.getKeys())
  52. {
  53. for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
  54. {
  55. if ( kpd.key[i].stateChanged ) // Only find keys that have changed state.
  56. {
  57. switch (kpd.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
  58. case PRESSED:
  59. msg = " PRESSED.";
  60.  
  61.  
  62.  
  63. Serial.print("Key ");
  64. Serial.print(kpd.key[i].kchar);
  65. Serial.println(msg);
  66. // release all the keys at the same instant
  67. Keyboard.set_key1(kpd.key[i].kchar);
  68. Keyboard.send_now();
  69.  
  70. //Keyboard.set_key1(0);
  71. //Keyboard.send_now();
  72. if (kpd.key[i].kchar == char(KEY_LEFT_SHIFT)) {
  73. Serial.print("Shift ");
  74. Keyboard.set_modifier(MODIFIERKEY_SHIFT);
  75. Keyboard.send_now();
  76. x=1;
  77.  
  78. }
  79.  
  80. break;
  81.  
  82. case HOLD:
  83. msg = " HOLD.";
  84. //Keyboard.set_modifier(MODIFIERKEY_SHIFT);
  85. //Keyboard.send_now();
  86.  
  87. Keyboard.set_key1(kpd.key[i].kchar);
  88. Keyboard.send_now();
  89.  
  90. break;
  91. case RELEASED:
  92. msg = " RELEASED.";
  93. Serial.println(msg);
  94. Keyboard.set_key1(0);
  95. Keyboard.send_now();
  96. if (kpd.key[i].kchar == char(KEY_LEFT_SHIFT)) {
  97. Serial.print("Shift Released ");
  98. Keyboard.set_modifier(0);
  99. Keyboard.send_now();
  100. x=0;
  101. }
  102.  
  103. break;
  104. case IDLE:
  105. msg = " IDLE.";
  106.  
  107. }
  108.  
  109. }
  110. }
  111. }
  112. } // End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement