Arduino Serial Write with Pushbutton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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