Skip to content

Instantly share code, notes, and snippets.

@mplinuxgeek
Created February 28, 2020 10:40
Show Gist options
  • Save mplinuxgeek/065da0510cdefafb0d9fa859b266bdc0 to your computer and use it in GitHub Desktop.
Save mplinuxgeek/065da0510cdefafb0d9fa859b266bdc0 to your computer and use it in GitHub Desktop.
#include "Keyboard.h"
const int buttonPin = 4; // input pin for pushbutton
const int timePin = 10; // input pin for pushbutton
const int time_Ground = 16; // input pin for pushbutton
const int LED_Ground = 8; // input pin for pushbutton
const int LED = 9; // input pin for pushbutton
int previousButtonState = HIGH; // for checking the state of a pushButton
void setup() {
// make the pushButton pin an input:
pinMode(buttonPin, INPUT_PULLUP);
pinMode(timePin, INPUT_PULLUP);
pinMode(LED_Ground, OUTPUT);
pinMode(time_Ground, OUTPUT);
pinMode(LED, OUTPUT);
digitalWrite(LED_Ground, LOW);
// initialize control over the keyboard:
Keyboard.begin();
}
void loop() {
digitalWrite(LED, HIGH);
// read the pushbutton:
int buttonState = digitalRead(buttonPin);
int timeState = digitalRead(timePin);
// if the button state has changed, and it's currently pressed:
if ((buttonState != previousButtonState) && (buttonState == LOW)) {
// type out a message
Keyboard.print(" ");
digitalWrite(LED, LOW);
if (timeState == LOW) {
delay(30000);
} else {
delay(50);
}
}
// 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