User Tools

Site Tools


arduino:serial_communication

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous 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:​arduino_crash_course:​serial_communication|here]].
- +
-===== Switch controlled LED with serial reporting ===== +
-<file c 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 +
-+
-</​file>​+
arduino/serial_communication.txt · Last modified: 2012/09/14 01:19 by mithat