Last active
February 7, 2024 07:45
-
-
Save adriy-be/d0f2008ef26b59ddd5eab7e66b36baf0 to your computer and use it in GitHub Desktop.
arduino_keyboard_password
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
/*See HID Project documentation for more information about the keyboard API: | |
https://github.com/NicoHood/HID/wiki/Keyboard-API | |
This board have a dip switch to encode a digit whos is in the password | |
Push button to enter the password with the encoded digit | |
*/ | |
#define HID_CUSTOM_LAYOUT | |
#define LAYOUT_FRENCH_BELGIAN | |
#include <HID-Project.h> | |
/* Time to wait after each key press/release so that it gets picked up by the | |
* host system [ms]. | |
*/ | |
#define KEYDELAY 5 | |
void printPw(); | |
/*unlock sequence delay { min1, max1, min2, max2, ..., 0 } */ | |
int unlockSequence[] = {100, 2000, 100, 2000, 0}; | |
// int unlockSequence[] = {0}; // lock was disabled | |
// pwPatern must be have a %d | |
const char * pwPatern = "TestPasswordChangeMe#%d"; | |
char pw[200]; | |
int iPw = 0; | |
void setup() { | |
Serial.begin(9600); | |
BootKeyboard.begin(); | |
BootKeyboard.releaseAll(); | |
for(int i = 2 ; i<= 9 ; i++) | |
{ | |
pinMode(i, INPUT_PULLUP); | |
} | |
pinMode(21, INPUT_PULLUP); | |
unsigned long lastTime = millis(); | |
unsigned long CurrentTime = millis(); | |
unsigned long dt = 0; | |
int unlockSequencei = 0; | |
bool pass = false; | |
bool push = false; | |
while(pass == false) | |
{ | |
if(unlockSequence[unlockSequencei*2] == 0) | |
pass = true; | |
push = false; | |
lastTime = millis(); | |
while(digitalRead(21) == 0) { push = true; delay(10); } | |
CurrentTime = millis(); | |
if(push) | |
{ | |
dt = CurrentTime - lastTime; | |
Serial.println(dt); | |
if(dt > unlockSequence[unlockSequencei*2] && dt < unlockSequence[unlockSequencei*2+1]) | |
unlockSequencei++; | |
else | |
unlockSequencei = 0; | |
} | |
} | |
printPw(); | |
} | |
void loop() { | |
if(digitalRead(21) == 0) | |
{ | |
printPw(); | |
} | |
} | |
void printPw() | |
{ | |
// get the number to enter in the password | |
iPw = 0; | |
for(int i = 2, ii = 0 ; i <= 9 ; i++, ii++) | |
{ | |
if(digitalRead(i) == 0) | |
{ | |
iPw |= 1<<ii; | |
} | |
} | |
sprintf(pw, pwPatern, iPw); | |
// push the password on the "virtual" keyboard | |
char * c = pw; | |
do{ | |
BootKeyboard.press(*c); | |
delay (KEYDELAY); | |
BootKeyboard.release(*c); | |
delay (KEYDELAY); | |
}while(*(++c) != '\0'); | |
BootKeyboard.press(KEY_ENTER); | |
delay (KEYDELAY); | |
BootKeyboard.release(KEY_ENTER); | |
delay (KEYDELAY); | |
BootKeyboard.releaseAll(); | |
delay (1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment