arduino:serial_communication
This is an old revision of the document!
Serial Communication
Switch controlled LED with serial reporting
- LightSwitchMonitored.ino
/* LightSwitchMonitored Turn an LED on and off and send switch state to serial monitor */ int pushButtonPin = 2; // connect the push button to digital pin 2 int ledPin = 13; // connect the LED to pin 13 void setup() { Serial.begin(9600); // initialize serial communication at 9600 bits/second pinMode(pushButtonPin, INPUT); // make the pushbutton's pin an input digitalWrite(pushButtonPin, HIGH); // turn on pullup resistors pinMode(ledPin, OUTPUT); // make LED's pin an output } void loop() { int buttonState = digitalRead(pushButtonPin); // read the input pin // set LED state accordingly if (buttonState == LOW) // if the button is pushed digitalWrite(ledPin, HIGH); // turn the LED on else // otherwise digitalWrite(ledPin, LOW); // turn the LED off Serial.println(buttonState); // print out state of button delay(500); // delay between reads }
arduino/serial_communication.1347584675.txt.gz · Last modified: 2012/09/14 01:04 by mithat