arduino:arduino_crash_course:serial_communication
Differences
This shows you the differences between two versions of the page.
Next revisionBoth sides next revision | |||
arduino:arduino_crash_course:serial_communication [2012/09/14 01:18] – created mithat | arduino:arduino_crash_course:serial_communication [2012/11/03 21:20] – mithat | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Serial Communication ====== | ====== Serial Communication ====== | ||
+ | |||
+ | //Tools > Serial Monitor// | ||
===== Switch controlled LED with serial reporting ===== | ===== Switch controlled LED with serial reporting ===== | ||
Line 7: | Line 9: | ||
Turn an LED on and off and send switch state to serial monitor | 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 pushButtonPin = 2; // connect the push button to digital pin 2 | ||
int ledPin = 13; // connect the LED to pin 13 | int ledPin = 13; // connect the LED to pin 13 | ||
- | + | ||
void setup() { | void setup() { | ||
Serial.begin(9600); | Serial.begin(9600); | ||
Line 22: | Line 24: | ||
void loop() { | void loop() { | ||
int buttonState = digitalRead(pushButtonPin); | int buttonState = digitalRead(pushButtonPin); | ||
- | + | ||
// set LED state accordingly | // set LED state accordingly | ||
if (buttonState == LOW) // if the button is pushed | if (buttonState == LOW) // if the button is pushed | ||
Line 28: | Line 30: | ||
else // otherwise | else // otherwise | ||
digitalWrite(ledPin, | digitalWrite(ledPin, | ||
- | + | ||
Serial.println(buttonState); | Serial.println(buttonState); | ||
delay(500); | delay(500); | ||
} | } | ||
</ | </ |
arduino/arduino_crash_course/serial_communication.txt · Last modified: 2012/11/12 18:23 by mithat