Created
September 5, 2020 09:06
-
-
Save speendo/c4001a6bf2fdecce148a2c1094cc10fd to your computer and use it in GitHub Desktop.
This file contains 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 "Keyboard.h" | |
const int buttonPin = 11; // input pin for pushbutton | |
int previousButtonState = HIGH; // for checking the state of a pushButton | |
int counter = 0; // button push counter | |
int prevTime = 0; | |
void setup() { | |
// make the pushButton pin an input: | |
pinMode(buttonPin, INPUT); | |
// initialize control over the keyboard: | |
Keyboard.begin(); | |
} | |
void loop() { | |
// read the pushbutton: | |
int buttonState = digitalRead(buttonPin); | |
// if the button state has changed, | |
if ((buttonState != previousButtonState) && (buttonState == HIGH)) { | |
prevTime = millis(); | |
int threshold = 0; | |
while (threshold <= 1000) { | |
int curTime = millis(); | |
if (curTime - prevTime >= threshold) { | |
Keyboard.print("Last Message before "); | |
Keyboard.print(curTime - prevTime); | |
Keyboard.println(" millis."); | |
threshold = threshold+10; | |
prevTime = millis(); | |
} | |
} | |
} | |
// save the current button state for comparison next time: | |
previousButtonState = buttonState; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment