Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.