// Define maximum and minimum pin numbers that will be tested.
// max_pin is usually set to the FPC connector size. min_pin is usually set to 1. The routine will start testing at pin 1 and go up to the max pin size.
// The max and min pin values can be adjusted to exclude testing the FPC traces at the edges if they are reported as shorted. An example would be if pin 1
// and pin 34 are both grounds. They will be reported as tied together but they are not needed by the key matrix. In this case, set the
// min_pin to 2 and the max_pin to 33.
//
intmax_pin=33;// the keyboard FPC connector pin count. If set to 34, unsolder the LED or the code won't work
intmin_pin=1;// the first pin to be tested on the FPC connector (usually pin 1)
//
// load the key codes used in sending usb numbers, tab, and down arrow
intkey_1=KEY_1;
intkey_2=KEY_2;
intkey_3=KEY_3;
intkey_4=KEY_4;
intkey_5=KEY_5;
intkey_6=KEY_6;
intkey_7=KEY_7;
intkey_8=KEY_8;
intkey_9=KEY_9;
intkey_0=KEY_0;
intkey_tab=KEY_TAB;
intkey_down=KEY_DOWN;
//
// Function to set a pin as an input with a pullup so it's high unless grounded by a key press
voidgo_z(intpin)
{
pinMode(pin,INPUT_PULLUP);
digitalWrite(pin,HIGH);
}
// Function to set a pin as an output and drive it to a logic low (0 volts)
voidgo_0(intpin)
{
pinMode(pin,OUTPUT);
digitalWrite(pin,LOW);
}
// Function to send numbers over USB for display on an editor
voidusb_num(intnum)// the numbers 0 thru 33 are sent over usb as 1 thru 34
{
switch(num){
case0:
Keyboard.set_key1(key_1);
Keyboard.send_now();
break;
case1:
Keyboard.set_key1(key_2);
Keyboard.send_now();
break;
case2:
Keyboard.set_key1(key_3);
Keyboard.send_now();
break;
case3:
Keyboard.set_key1(key_4);
Keyboard.send_now();
break;
case4:
Keyboard.set_key1(key_5);
Keyboard.send_now();
break;
case5:
Keyboard.set_key1(key_6);
Keyboard.send_now();
break;
case6:
Keyboard.set_key1(key_7);
Keyboard.send_now();
break;
case7:
Keyboard.set_key1(key_8);
Keyboard.send_now();
break;
case8:
Keyboard.set_key1(key_9);
Keyboard.send_now();
break;
case9:
Keyboard.set_key1(key_1);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_0);
Keyboard.send_now();
break;
case10:
Keyboard.set_key1(key_1);
Keyboard.send_now();
delay(50);
Keyboard.set_key1(0);
Keyboard.send_now();
delay(50);
Keyboard.set_key2(key_1);
Keyboard.send_now();
break;
case11:
Keyboard.set_key1(key_1);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_2);
Keyboard.send_now();
break;
case12:
Keyboard.set_key1(key_1);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_3);
Keyboard.send_now();
break;
case13:
Keyboard.set_key1(key_1);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_4);
Keyboard.send_now();
break;
case14:
Keyboard.set_key1(key_1);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_5);
Keyboard.send_now();
break;
case15:
Keyboard.set_key1(key_1);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_6);
Keyboard.send_now();
break;
case16:
Keyboard.set_key1(key_1);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_7);
Keyboard.send_now();
break;
case17:
Keyboard.set_key1(key_1);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_8);
Keyboard.send_now();
break;
case18:
Keyboard.set_key1(key_1);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_9);
Keyboard.send_now();
break;
case19:
Keyboard.set_key1(key_2);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_0);
Keyboard.send_now();
break;
case20:
Keyboard.set_key1(key_2);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_1);
Keyboard.send_now();
break;
case21:
Keyboard.set_key1(key_2);
Keyboard.send_now();
delay(50);
Keyboard.set_key1(0);
Keyboard.send_now();
delay(50);
Keyboard.set_key2(key_2);
Keyboard.send_now();
break;
case22:
Keyboard.set_key1(key_2);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_3);
Keyboard.send_now();
break;
case23:
Keyboard.set_key1(key_2);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_4);
Keyboard.send_now();
break;
case24:
Keyboard.set_key1(key_2);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_5);
Keyboard.send_now();
break;
case25:
Keyboard.set_key1(key_2);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_6);
Keyboard.send_now();
break;
case26:
Keyboard.set_key1(key_2);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_7);
Keyboard.send_now();
break;
case27:
Keyboard.set_key1(key_2);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_8);
Keyboard.send_now();
break;
case28:
Keyboard.set_key1(key_2);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_9);
Keyboard.send_now();
break;
case29:
Keyboard.set_key1(key_3);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_0);
Keyboard.send_now();
break;
case30:
Keyboard.set_key1(key_3);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_1);
Keyboard.send_now();
break;
case31:
Keyboard.set_key1(key_3);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_2);
Keyboard.send_now();
break;
case32:
Keyboard.set_key1(key_3);
Keyboard.send_now();
delay(50);
Keyboard.set_key1(0);
Keyboard.send_now();
delay(50);
Keyboard.set_key2(key_3);
Keyboard.send_now();
break;
case33:
Keyboard.set_key1(key_3);
Keyboard.send_now();
delay(20);
Keyboard.set_key2(key_4);
Keyboard.send_now();
break;
}
delay(20);
Keyboard.set_key1(0);// clear out the key slots
Keyboard.set_key2(0);
Keyboard.send_now();
delay(20);
Keyboard.set_key1(key_tab);// Tab over to position for next number
Keyboard.send_now();
delay(20);
Keyboard.set_key1(0);// clear out the tab from the slot
Keyboard.send_now();
delay(20);
}
// Function to send a down arrow over usb to position for the next key