arduino:serial_communication
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
arduino:serial_communication [2012/09/14 01:04] – mithat | arduino:serial_communication [2012/09/14 01:19] (current) – mithat | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Serial Communication ====== | + | Moved [[arduino: |
- | + | ||
- | ===== Switch controlled LED with serial reporting ===== | + | |
- | <file c LightSwitchMonitored.ino> | + | |
- | /* | + | |
- | | + | |
- | 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); | + | |
- | + | ||
- | pinMode(pushButtonPin, | + | |
- | digitalWrite(pushButtonPin, | + | |
- | + | ||
- | pinMode(ledPin, | + | |
- | } | + | |
- | + | ||
- | void loop() { | + | |
- | int buttonState = digitalRead(pushButtonPin); | + | |
- | + | ||
- | // set LED state accordingly | + | |
- | if (buttonState == LOW) // if the button is pushed | + | |
- | digitalWrite(ledPin, | + | |
- | else // otherwise | + | |
- | digitalWrite(ledPin, | + | |
- | + | ||
- | Serial.println(buttonState); | + | |
- | delay(500); | + | |
- | } | + | |
- | </ | + |
arduino/serial_communication.txt · Last modified: 2012/09/14 01:19 by mithat