Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save federicocappelli/7f61d6bc2095cbc278df12519b721435 to your computer and use it in GitHub Desktop.
Save federicocappelli/7f61d6bc2095cbc278df12519b721435 to your computer and use it in GitHub Desktop.
sinclair_Spectrum_USB.ino
/*
* Toshiba T1000 Keyboard interpreter
*
* Converts signals from a T1000 keyboard's key matrix to a stndard USB keyboard when using a Teensy LC.
*
* 2017 Chad Boughton
*/
#include <Keypad.h>
const byte ROWS = 5;
const byte COLS = 8;
char keys[ROWS][COLS] = {
{KEY_1,KEY_2,KEY_3,KEY_4,KEY_5,KEY_6,KEY_7,KEY_8},
{KEY_9,KEY_0,KEY_A,KEY_B,KEY_C,KEY_D,KEY_E,KEY_F},
{KEY_G,KEY_H,KEY_I,KEY_J,KEY_K,KEY_L,KEY_M,KEY_N},
{KEY_O,KEY_P,KEY_Q,KEY_R,KEY_S,KEY_T,KEY_U,KEY_V},
{KEY_W,KEY_X,KEY_Y,KEY_Z,KEY_ENTER,KEY_TILDE,KEY_DELETE,KEY_BACKSPACE}
};
byte rowPins[ROWS] = {1,2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8,9,10,11,12,13}; //connect to the column pinouts of the keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
unsigned long loopCount;
unsigned long startTime;
String msg;
int x = 0;
void setup() {
Serial.begin(9600);
loopCount = 0;
startTime = millis();
msg = "";
}
void loop() {
loopCount++;
//char key = kpd.getKey();
if ( (millis()-startTime)>5000 ) {
//Serial.print("Average loops per second = ");
//Serial.println(loopCount/5);
startTime = millis();
loopCount = 0;
}
// Fills kpd.key[ ] array with up-to 10 active keys.
// Returns true if there are ANY active keys.
if (kpd.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
{
if ( kpd.key[i].stateChanged ) // Only find keys that have changed state.
{
switch (kpd.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED:
msg = " PRESSED.";
Serial.print("Key ");
Serial.print(kpd.key[i].kchar);
Serial.println(msg);
// release all the keys at the same instant
Keyboard.set_key1(kpd.key[i].kchar);
Keyboard.send_now();
//Keyboard.set_key1(0);
//Keyboard.send_now();
if (kpd.key[i].kchar == char(KEY_LEFT_SHIFT)) {
Serial.print("Shift ");
Keyboard.set_modifier(MODIFIERKEY_SHIFT);
Keyboard.send_now();
x=1;
}
break;
case HOLD:
msg = " HOLD.";
//Keyboard.set_modifier(MODIFIERKEY_SHIFT);
//Keyboard.send_now();
Keyboard.set_key1(kpd.key[i].kchar);
Keyboard.send_now();
break;
case RELEASED:
msg = " RELEASED.";
Serial.println(msg);
Keyboard.set_key1(0);
Keyboard.send_now();
if (kpd.key[i].kchar == char(KEY_LEFT_SHIFT)) {
Serial.print("Shift Released ");
Keyboard.set_modifier(0);
Keyboard.send_now();
x=0;
}
break;
case IDLE:
msg = " IDLE.";
}
}
}
}
} // End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment