Skip to content

Instantly share code, notes, and snippets.

@faaip
Created June 23, 2017 07:07
Show Gist options
  • Save faaip/a2623d12368dc32cb56e207f80d4e681 to your computer and use it in GitHub Desktop.
Save faaip/a2623d12368dc32cb56e207f80d4e681 to your computer and use it in GitHub Desktop.
const int buttonPin = 2; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
// Setup serial
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
Serial.println(1);
} else {
Serial.println(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment