Last active
July 2, 2020 14:31
-
-
Save JamesCordell/a28d685d53806f1fd9415c7557716b95 to your computer and use it in GitHub Desktop.
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
/* Simple USB Keyboard Example | |
Teensy becomes a USB keyboard and types characters | |
You must select Keyboard from the "Tools > USB Type" menu | |
This example code is in the public domain. | |
*/ | |
#define NUM_BUT 8 | |
int led = 11;//led | |
void but(int button) { | |
if (button == 0) { | |
Keyboard.print("none"); | |
//Keyboard.press(KEY_TAB); | |
//Keyboard.release(KEY_TAB); | |
//Keyboard.print(""); | |
} | |
if (button == 1) { | |
Keyboard.print("pw"); | |
} | |
if (button == 2) { | |
//Keyboard.print(""); | |
//Keyboard.press(KEY_TAB); | |
//Keyboard.release(KEY_TAB); | |
Keyboard.print("pw"); | |
} | |
if (button == 3) { | |
Keyboard.print(""); | |
} | |
if (button == 4) { | |
Keyboard.print(""); | |
} | |
if (button == 5) { | |
Keyboard.print("username"); | |
Keyboard.press(KEY_TAB); | |
Keyboard.release(KEY_TAB); | |
Keyboard.print(""); | |
} | |
if (button == 6) { | |
Keyboard.print("username"); | |
Keyboard.press(KEY_TAB); | |
Keyboard.release(KEY_TAB); | |
Keyboard.print("pw"); | |
} | |
if (button == 7) { | |
Keyboard.print("username"); | |
Keyboard.press(KEY_TAB); | |
Keyboard.release(KEY_TAB); | |
Keyboard.print("pw"); | |
} | |
} | |
int butArr[NUM_BUT]; | |
void setup() { | |
butArr[0] = 21;// usb top down anticlock | |
butArr[1] = 19; | |
butArr[2] = 16; | |
butArr[3] = 13; | |
butArr[4] = 10; | |
butArr[5] = 7; | |
butArr[6] = 4; | |
butArr[7] = 1; | |
pinMode(led, OUTPUT);//led | |
for (int i=0; i < NUM_BUT ;++i) { | |
pinMode(butArr[i], INPUT_PULLUP); | |
} | |
Serial.begin(57600); | |
Serial.println("Pushbutton bounce test:"); | |
} | |
int but_num =0; | |
bool unlock = false; | |
int passcode[] = {1,2,3,4,5,6 }; // passcode | |
int passcount=0; | |
long int ledcount=0; | |
void loop() { | |
if (but_num >= NUM_BUT){ | |
but_num =0; | |
} | |
byte buttonState = digitalRead(butArr[but_num]); | |
if (buttonState == LOW && unlock == false) { | |
if ( passcode[passcount] == but_num ) { | |
passcount++; | |
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(10); // wait for a second | |
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW | |
} else { | |
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(1000); // wait for a second | |
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW | |
exit(0); | |
} | |
if (passcount == 6) { | |
unlock = true; | |
for (int i =0; i < 6;++i) { | |
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(10); // wait for a second | |
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW | |
delay(100); | |
} | |
//Serial.print("unlocked"); | |
buttonState = HIGH; | |
} | |
delay(400); | |
} | |
if ( unlock == true ){ | |
if ( ledcount > 200000 ) { | |
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(5); // wait for a second | |
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW | |
ledcount=0; | |
} else { | |
ledcount++; | |
} | |
} | |
if (buttonState == LOW && unlock == true) { | |
//Serial.print("Pushbutton bounce test:"); | |
Serial.println(but_num); | |
but(but_num); | |
delay(1000); | |
} | |
but_num++; | |
} | |
// Your computer will receive these characters from a USB keyboard. | |
//Mouse.move(2, 2); | |
//Mouse.move(-2, -2); | |
//digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) | |
//delay(10); // wait for a second | |
//digitalWrite(led, LOW); // turn the LED off by making the voltage LOW | |
//delay(3000); // wait for a second | |
// typing too rapidly can overwhelm a PC | |
/* | |
Keyboard.println(); | |
delay(22000); | |
// press and hold CTRL | |
Keyboard.set_modifier(MODIFIERKEY_CTRL); | |
Keyboard.send_now(); | |
// press ALT while still holding CTRL | |
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT); | |
Keyboard.send_now(); | |
// press DELETE, while CLTR and ALT still held | |
Keyboard.set_key1(KEY_DELETE); | |
Keyboard.send_now(); | |
// release all the keys at the same instant | |
Keyboard.set_modifier(0); | |
Keyboard.set_key1(0); | |
Keyboard.send_now(); | |
delay(2000); | |
Keyboard.press(KEY_ENTER); // user agreement | |
Keyboard.release(KEY_ENTER); | |
delay(2000); | |
Keyboard.press(KEY_RIGHT); // vpn account | |
Keyboard.release(KEY_RIGHT); | |
delay(2000); | |
Keyboard.press(KEY_ENTER); // select | |
Keyboard.release(KEY_ENTER); | |
delay(2000); | |
Keyboard.print("username"); | |
Keyboard.press(KEY_TAB); | |
Keyboard.release(KEY_TAB); | |
Keyboard.print("pw"); | |
delay(20000); | |
Keyboard.print("username"); | |
Keyboard.press(KEY_TAB); | |
Keyboard.release(KEY_TAB); | |
Keyboard.print("pw"); | |
Keyboard.press(KEY_ENTER); | |
Keyboard.release(KEY_ENTER); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment