Made the code more readable and native.
This commit is contained in:
parent
485e474899
commit
f6d0db5d87
2 changed files with 66 additions and 64 deletions
114
Passkey.ino
114
Passkey.ino
|
|
@ -21,8 +21,10 @@
|
||||||
|
|
||||||
// The button pin
|
// The button pin
|
||||||
#define BUTTON_PIN 0
|
#define BUTTON_PIN 0
|
||||||
|
|
||||||
// The LED pin
|
// The LED pin
|
||||||
#define LED_PIN 1
|
#define LED_PIN 1
|
||||||
|
|
||||||
// The pause after last button press before executing a command
|
// The pause after last button press before executing a command
|
||||||
#define PAUSE 2000
|
#define PAUSE 2000
|
||||||
|
|
||||||
|
|
@ -30,72 +32,72 @@
|
||||||
unsigned long last;
|
unsigned long last;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
|
|
||||||
// Create blinker object
|
// Create Blinker object
|
||||||
Blinker blinker(LED_PIN);
|
Blinker Blinker(LED_PIN);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Set button pin to high.
|
// Set button pin to high.
|
||||||
pinMode(BUTTON_PIN, INPUT);
|
pinMode(BUTTON_PIN, INPUT);
|
||||||
// Set BUTTON_PIN pin to high because the button is connected
|
// Set BUTTON_PIN pin to high because the button is connected
|
||||||
// to GND when pressed and will go LOW
|
// to GND when pressed and will go LOW
|
||||||
digitalWrite(BUTTON_PIN, HIGH);
|
digitalWrite(BUTTON_PIN, HIGH);
|
||||||
|
|
||||||
// Set blink effect (ON, OFF) in milliseconds
|
// Set blink effect (ON, OFF) in milliseconds
|
||||||
blinker.setDelay(25, 9075);
|
Blinker.setDelay(25, 9075);
|
||||||
// Start LED blink effect
|
// Start LED blink effect
|
||||||
blinker.start();
|
Blinker.start();
|
||||||
|
|
||||||
// Initialize HID
|
// Initialize HID
|
||||||
DigiKeyboard.delay(0);
|
DigiKeyboard.delay(0);
|
||||||
DigiKeyboard.sendKeyStroke(0);
|
DigiKeyboard.sendKeyStroke(0);
|
||||||
|
|
||||||
// Light up the LED for a second to show that passkey is ready
|
// Light up the LED for a second to show that passkey is ready
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
digitalWrite(LED_PIN, HIGH);
|
digitalWrite(LED_PIN, HIGH);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
digitalWrite(LED_PIN, LOW);
|
digitalWrite(LED_PIN, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Invoke the Blinker
|
// Invoke the Blinker
|
||||||
blinker.blink();
|
Blinker.blink();
|
||||||
|
|
||||||
// Read button state
|
// Read button state
|
||||||
if (digitalRead(BUTTON_PIN) == LOW) {
|
if (digitalRead(BUTTON_PIN) == LOW) {
|
||||||
// Button is pressed
|
// Button is pressed
|
||||||
count++;
|
count++;
|
||||||
digitalWrite(LED_PIN, HIGH);
|
digitalWrite(LED_PIN, HIGH);
|
||||||
// Wait until button is released
|
// Wait until button is released
|
||||||
while (digitalRead(BUTTON_PIN) == LOW) {
|
while (digitalRead(BUTTON_PIN) == LOW) {
|
||||||
delay(1);
|
delay(1);
|
||||||
|
}
|
||||||
|
// Set the last press timestamp
|
||||||
|
last = millis();
|
||||||
|
digitalWrite(LED_PIN, LOW);
|
||||||
}
|
}
|
||||||
// Set the last press timestamp
|
|
||||||
last = millis();
|
|
||||||
digitalWrite(LED_PIN, LOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait PAUSE time before executing a command
|
// Wait PAUSE time before executing a command
|
||||||
if (count > 0 && (millis() - last) >= PAUSE) {
|
if (count > 0 && (millis() - last) >= PAUSE) {
|
||||||
// The switch case is the number of button presses
|
// The switch case is the number of button presses
|
||||||
switch (count) {
|
switch (count) {
|
||||||
case 1:
|
case 1:
|
||||||
DigiKeyboard.println(passwords[0]);
|
DigiKeyboard.println(passwords[0]);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
DigiKeyboard.println(passwords[1]);
|
DigiKeyboard.println(passwords[1]);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
DigiKeyboard.println(passwords[2]);
|
DigiKeyboard.println(passwords[2]);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
// You can use print instead of println if you don't want
|
// You can use print instead of println if you don't want
|
||||||
// to hit enter automatically after inserting the password
|
// to hit enter automatically after inserting the password
|
||||||
DigiKeyboard.print(passwords[3]);
|
DigiKeyboard.print(passwords[3]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
// Reset the counter
|
||||||
|
count = 0;
|
||||||
}
|
}
|
||||||
// Reset the counter
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
Passwords.h
16
Passwords.h
|
|
@ -6,12 +6,12 @@
|
||||||
// on the passkey unusable for others in case you've lost
|
// on the passkey unusable for others in case you've lost
|
||||||
// your passkey. E.g.: WhatAWonderfulWorld -> then press the button.
|
// your passkey. E.g.: WhatAWonderfulWorld -> then press the button.
|
||||||
const char *passwords[] = {
|
const char *passwords[] = {
|
||||||
// passwords[0]
|
// passwords[0]
|
||||||
"n0Emb871NAQPSIqBoldh8R7UDaNhncF7Pt60Amdo6GWdTdAPwVBi2A3KU8x8DTCRo6GWdTdXNn2wLh3SUbxVWQvFDVPtatDg",
|
"n0Emb871NAQPSIqBoldh8R7UDaNhncF7Pt60Amdo6GWdTdAPwVBi2A3KU8x8DTCRo6GWdTdXNn2wLh3SUbxVWQvFDVPtatDg",
|
||||||
// passwords[1]
|
// passwords[1]
|
||||||
"oaxt6e3lSgflOuJ3C6Q6sUb5gvmvI5IEPFku5fqcbxJljBOUblHIT121wCu",
|
"oaxt6e3lSgflOuJ3C6Q6sUb5gvmvI5IEPFku5fqcbxJljBOUblHIT121wCu",
|
||||||
// passwords[2]
|
// passwords[2]
|
||||||
"jUgKGBtiJ0iNN1Ok9vejrXNn2wLh3SUbxVWQvFDVPtat0OxJlKU8x8DTCRo6GWdTdAPwVBi2A3KUrTKQwjUgK",
|
"jUgKGBtiJ0iNN1Ok9vejrXNn2wLh3SUbxVWQvFDVPtat0OxJlKU8x8DTCRo6GWdTdAPwVBi2A3KUrTKQwjUgK",
|
||||||
// passwords[3]
|
// passwords[3]
|
||||||
"G57dFnXsPUnRq1eC1CjrGxpCjuiJFlDti54W6wBS9Ro6GWdTdAPwVBi2A3KU8x8KGBtiJ0iNN1Ok9vejrXNn2wLhH"
|
"G57dFnXsPUnRq1eC1CjrGxpCjuiJFlDti54W6wBS9Ro6GWdTdAPwVBi2A3KU8x8KGBtiJ0iNN1Ok9vejrXNn2wLhH"
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue