First version with a button and added the Blinker library to the source root.

This commit is contained in:
Johannes Findeisen 2022-11-29 03:51:52 +01:00
commit 15e33b531f
9 changed files with 246 additions and 31 deletions

View file

@ -1,56 +1,82 @@
#include "Blinker.h"
#include "DigiKeyboard.h"
#include "ezButton.h"
int ACTION_PIN = 0;
int LED_PIN = 1;
// the button pin
#define BUTTON_PIN 0
// the LED pin
#define LED_PIN 1
// the pause after last button press before executing a command
#define PAUSE 2000
// local variables
unsigned long last;
unsigned int count;
// create blinker
Blinker blinker(LED_PIN);
ezButton button(ACTION_PIN);
char *passwords[] = {
"0qMpI7Af06Z4XnMDhzXROnEgtuxPsCPLiBJT90Rb1F2BZKCmIhpLOdxtBpurUa9Tg",
"1qMpI7Af06Z4XnMDhzXROnEgtuxPsCPLiBJT90Rb1F2BZKCmIhpLOdxtBpurUa9Tg",
"2qMpI7Af06Z4XnMDhzXROnEgtuxPsCPLiBJT90Rb1F2BZKCmIhpLOdxtBpurUa9Tg",
"3qMpI7Af06Z4XnMDhzXROnEgtuxPsCPLiBJT90Rb1F2BZKCmIhpLOdxtBpurUa9Tg"
// the list of available passwords
const char *passwords[] = {
"PASSWORD1",
"PASSWORD2",
"PASSWORD3",
"PASSWORD4"
};
void setup() {
// set button pin to high
pinMode(BUTTON_PIN, INPUT);
digitalWrite(BUTTON_PIN, HIGH);
// light up the LED for a second to show that passkey is ready
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
delay(1000);
digitalWrite(LED_PIN, LOW);
// set blink effect (ON, OFF) in milliseconds
blinker.setDelay(25, 10000);
blinker.start();
button.setCountMode(COUNT_RISING);
button.setDebounceTime(0);
// initialize HID
DigiKeyboard.delay(0);
DigiKeyboard.sendKeyStroke(0);
}
void loop() {
// start LED blink effect
blinker.blink();
button.loop();
/*digitalWrite(LED_PIN, HIGH);
delay(25);
digitalWrite(1, LOW);
delay(10000);*/
if(button.isPressed()) {
//DigiKeyboard.println("Hello World!");
/*DigiKeyboard.println(passwords[0]);
DigiKeyboard.println(passwords[1]);
DigiKeyboard.println(passwords[2]);
DigiKeyboard.println(passwords[3]);*/
// read button state
if (digitalRead(BUTTON_PIN) == LOW) {
// button is pressed
last = millis();
count++;
// wait until button is released
while(digitalRead(BUTTON_PIN) == LOW) {
delay(1);
}
}
unsigned long count = button.getCount();
// press button five times to get a password
if(count == 5) {
//DigiKeyboard.println(count);
DigiKeyboard.println(passwords[0]);
button.resetCount();
// wait PAUSE time before executing a command
if (count > 0 && (millis() - last) >= PAUSE) {
// the switch case is the number of button presses
switch(count) {
case 1:
DigiKeyboard.println(passwords[0]);
break;
case 2:
DigiKeyboard.println(passwords[1]);
break;
case 3:
DigiKeyboard.println(passwords[2]);
break;
case 5:
DigiKeyboard.println(passwords[3]);
break;
default:
break;
}
count = 0; // reset the counter
}
}