Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
const int pins[16][4] = {
{LOW,LOW,LOW,LOW},
{LOW,LOW,LOW,HIGH},
{LOW,LOW,HIGH,LOW},
{LOW,LOW,HIGH,HIGH},
{LOW,HIGH,LOW,LOW},
{LOW,HIGH,LOW,HIGH},
{LOW,HIGH,HIGH,LOW},
{LOW,HIGH,HIGH,HIGH},
{HIGH,LOW,LOW,LOW},
{HIGH,LOW,LOW,HIGH},
{HIGH,LOW,HIGH,LOW},
{HIGH,LOW,HIGH,HIGH},
{HIGH,HIGH,LOW,LOW},
{HIGH,HIGH,LOW,HIGH},
{HIGH,HIGH,HIGH,LOW},
{HIGH,HIGH,HIGH,HIGH}
};
const unsigned char key_code[16][8] = {
{0,0,0,0,0,0,0,0},
{0,68,67,66,0,0,40,0},
{8,7,6,5,4,47,10,9},
{8,15,14,13,12,11,18,17},
{24,23,22,21,20,19,26,50},
{24,137,48,29,28,27,45,46},
{55,33,32,31,30,39,36,35},
{55,54,51,52,38,37,135,56},
{0,227,42,79,82,76,224,229},
{226,61,60,59,58,53,41,44},
{0,0,70,80,81,43,57,65},
{0,0,0,0,64,63,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}
};
void setup() {
Serial.begin(9600);
// set OUTPUT pins(analog in/out)
for(int i=14;i<=17;i++){
pinMode(i,OUTPUT);
}
// set INPUT pins(digital in/out)
for(int i=2;i<=9;i++){
pinMode(i,INPUT);
digitalWrite(i,HIGH);
}
}
void loop() {
unsigned char buffer[8] = {0};
int seek = 2;
for(int column=0;column<16;column++){
for(int i=14;i<=17;i++){
digitalWrite(i,pins[column][i-14]);
}
for(int i=2,row=0;i<=9;i++,row++){
if(digitalRead(i)==LOW)
{
if(key_code[column][row]==0xe1){buffer[0]+=0x02;continue;}//lsh
if(key_code[column][row]==0xe0){buffer[0]+=0x01;continue;}//lct
if(key_code[column][row]==0xe2){buffer[0]+=0x04;continue;}//lal
if(key_code[column][row]==0xe5){buffer[0]+=0x20;continue;}//rsh
if(searchBuffer(buffer,key_code[column][row]))continue;
buffer[seek] = key_code[column][row];
seek++;
}
}
}
Serial.write(buffer,8);
}
int searchBuffer(unsigned char *buffer,unsigned char c){
for(int k=2;k<8;k++){
if(buffer[k]==c)return 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment