Last active
May 15, 2019 10:51
-
-
Save tcz001/f5f683a2212fd6c68322062d204701ef to your computer and use it in GitHub Desktop.
yubikey
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
#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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BOM:
Digispark
A touch button