Skip to content

Instantly share code, notes, and snippets.

@extrasleepy
Last active August 29, 2015 14:11
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 extrasleepy/c2807755b6276da6bdac to your computer and use it in GitHub Desktop.
Save extrasleepy/c2807755b6276da6bdac to your computer and use it in GitHub Desktop.
Arduino Serial Write with Pushbutton
// Code for sensing a switch status and writing the value to the serial port.
byte switchPin = 2; // Switch connected to pin 2
void setup() {
pinMode(switchPin, INPUT); // Set pin 2 as an input
Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop() {
if (digitalRead(switchPin) == HIGH) { // If switch is ON,
Serial.write(1); // send 1 to Serial (Processing)
} else { // If the switch is not ON,
Serial.write(0); // send 0 to Serial (Processing)
}
delay(100); // Wait 100 milliseconds
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment