Skip to content

Instantly share code, notes, and snippets.

@speendo
Created September 5, 2020 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save speendo/c4001a6bf2fdecce148a2c1094cc10fd to your computer and use it in GitHub Desktop.
Save speendo/c4001a6bf2fdecce148a2c1094cc10fd to your computer and use it in GitHub Desktop.
#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