Skip to content

Instantly share code, notes, and snippets.

@tcz001
Last active May 15, 2019 10:51
Show Gist options
  • Save tcz001/f5f683a2212fd6c68322062d204701ef to your computer and use it in GitHub Desktop.
Save tcz001/f5f683a2212fd6c68322062d204701ef to your computer and use it in GitHub Desktop.
yubikey
#include "DigiKeyboard.h"
void setup() {
pinMode(0, INPUT);
pinMode(1, OUTPUT);
//blink twice
digitalWrite(1, HIGH);
delay(100);
digitalWrite(1, LOW);
delay(100);
digitalWrite(1, HIGH);
delay(100);
digitalWrite(1, LOW);
}
int s = 0;
int touch = 0;
int mode = 0;
void loop() {
s = digitalRead(0);
if (s != 0) {
touch++;
delay(10);
} else {
if (touch >= 3 && touch <= 100) {
mode = 1;
touch = 0;
} else {
mode = 0;
touch = 0;
}
}
if (touch > 100) {
mode = 2;
touch = 0;
}
if (mode == 1) {
//blink once
digitalWrite(1, HIGH);
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.println("Mode 1!");
mode = 0;
DigiKeyboard.delay(1000);
} else if (mode == 2) {
//blink twice
digitalWrite(1, HIGH);
delay(100);
digitalWrite(1, LOW);
delay(100);
digitalWrite(1, HIGH);
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.println("Mode 2!");
// wait until button released
while (s != 0) {
s = digitalRead(0);
}
mode = 0;
DigiKeyboard.delay(1000);
} else {
digitalWrite(1, LOW);
}
}
@tcz001
Copy link
Author

tcz001 commented May 15, 2019

BOM:

Digispark
A touch button

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment