Created
May 15, 2016 01:30
-
-
Save Lana-chan/065eb6829311e6660fdff7ce2d5030cd to your computer and use it in GitHub Desktop.
Simple Arduino Mega sketch for reading a CP500 keyboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const char* keysupp = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ 0!\"#$%&'()*+<=>?"; | |
const char* keysdwn = "@abcdefghijklmnopqrstuvwxyz 0123456789:;,-./"; | |
const byte colCount = 8; | |
const byte colStart = 22; | |
const byte rowStart = colStart + colCount; | |
boolean pressed; | |
boolean held; | |
boolean shift; | |
void setup() { | |
for(int i = 0; i < 8; i++) { | |
pinMode(i+colStart, OUTPUT); | |
digitalWrite(i+rowStart, HIGH); | |
pinMode(i+rowStart, INPUT_PULLUP); | |
} | |
Serial.begin(9600); | |
} | |
void loop() { | |
pressed = false; | |
for(int i = 0; i < 8; i++) { | |
byte col = i + colStart; | |
digitalWrite(col, LOW); | |
delay(1); | |
for(int j = 0; j < 8; j++) { | |
if(digitalRead(j + rowStart) == LOW) { | |
pressed = true; | |
if(!held) { | |
if(i == 6) { | |
if(j == 0) Serial.println(); | |
if(j == 7) Serial.print(" "); | |
} else if(i == 7) { | |
shift = !shift; | |
} else { | |
if(shift) Serial.print(keysupp[i*colCount+j]); | |
else Serial.print(keysdwn[i*colCount+j]); | |
} | |
} | |
} | |
} | |
digitalWrite(col, HIGH); | |
} | |
held = pressed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment