Skip to content

Instantly share code, notes, and snippets.

@darkwave
Created April 2, 2016 14:02
Show Gist options
  • Save darkwave/a8cb83ea305d5a8599ba14a4b4bea041 to your computer and use it in GitHub Desktop.
Save darkwave/a8cb83ea305d5a8599ba14a4b4bea041 to your computer and use it in GitHub Desktop.
BottonINO
#include "Keyboard.h"
const int buttonPin = 4; // input pin for pushbutton
int previousButtonState = HIGH; // for checking the state of a pushButton
int counter = 0; // button push counter
void setup() {
// make the pushButton pin an input "pullup":
pinMode(buttonPin, INPUT_PULLUP);
// 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)
// and it's currently pressed:
&& (buttonState == HIGH)) {
// increment the button counter
counter++;
// type out a message
Keyboard.write(65);
}
// 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