PowenKo > arduino > Serial

March 23, 2012   ·   0 Comments

IMAG2361 copy

send

// Sends "A"s through the serial port every second

// 'Setup' function
void setup()
{
  // Start the UART at 9600 bits-per-second (baud)
  Serial.begin(9600);
}

// Main loop
void loop()
{
  // Print an A through the UART
  Serial.println("A");

  // Pause 1 second
  delay(1000);
}

read

// Receives data from the serial port

// Create a variable called 'val'

#include <SoftwareSerial.h>
int val = 0;

SoftwareSerial mySerial(2, 3); // RX, TX
// 'Setup' function
void setup()
{
  // Start the UART at 9600 baud
  Serial.begin(9600);
    mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

// Main loop
void loop()
{
  // If there is data ready...
  if (mySerial.available())
  {
    // ...Set the value of our variable to whatever the data is
    val = mySerial.read();

    // Print the data back through the UART
    Serial.println(val);
  }
}

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Hardware22

Hardware

Amazon

adsbygoogle

Recent Posts

Categories

Amazon