[gnoduino: 3/4] Squashed 'libraries/' changes from 1931ff5..ddb94de



commit 7be55d6ac3d3a42fcdfdf934e6eb9de94ab3316f
Author: Lucian Langa <lucilanga gnome org>
Date:   Tue Jun 12 23:53:13 2012 +0200

    Squashed 'libraries/' changes from 1931ff5..ddb94de
    
    ddb94de just change a comment to make more sense
    0c4188b fix SPI init issues as described http://code.google.com/p/arduino/issues/detail?id=888.  Tested using qt1110 (mode 3) on a mega and WS5100 (webserver example sketch) chips on a etherten
    9ae53c3 Updated SoftwareSerial examples so that they work easier with Leonardo and Mega
    1feb590 Merge branch 'master' of github.com:arduino/Arduino into LUFA_bootloader
    b96cb01 spell check on PachubeClientString
    67cf58e Added Cosm Clients to replace Pachube Clients due to Pachube.com rebranding
    3b7c851 Merge branch 'master' of github.com:arduino/Arduino
    bc8817a Servo bug that would sometimes cause skipping.
    3f0595c Merge pull request #70 from johannrichard/ethernet-close_wait
    af8588d Merge branch 'master' of github.com:arduino/Arduino into LUFA_bootloader
    2a6108c Update to WebClientRepeating comments
    6816ca9 Added WebClientRepeating example
    db13f95 Removed Serial.begin() inside examples where not needed
    e5b47ff updated URLs in LiquidCrystal examples
    7d1f132 Updated all comments for while (!Serial) additions to serial-based examples
    6a8a331 Fix for CLOSE_WAIT Bug
    1e92dae Updated all serial in setup examples with a note about the serial check
    338f2df Added Serial port check to all examples using Serial statements in the setup
    dfd47b8 Merge branch 'master' of github.com:arduino/Arduino into LUFA_bootloader
    44d4048 Merge branch 'master' of github.com:arduino/Arduino into LUFA_bootloader
    b7e0c83 Merge branch 'master' of github.com:arduino/Arduino into LUFA_bootloader
    527ec1c Merge branch 'master' of github.com:arduino/Arduino into LUFA_bootloader
    1910706 Merge branch 'master' of github.com:arduino/Arduino into LUFA_bootloader
    75f9e0b Merge branch 'master' of github.com:arduino/Arduino into LUFA_bootloader
    e8c03ce Merge branch 'master' of github.com:arduino/Arduino into new-extension
    efb13bc Merge branch 'master' of github.com:arduino/32U4 into new-extension
    6910532 Fixing ethernet library on Leonardo (correcting SS pin for 32U4).
    
    git-subtree-dir: libraries
    git-subtree-split: ddb94de9afe95374d52a800ae679fe28e7f5e01e

 EEPROM/examples/eeprom_read/eeprom_read.ino        |    4 +
 Ethernet/EthernetClient.cpp                        |    2 +-
 Ethernet/examples/ChatServer/ChatServer.ino        |    9 +-
 Ethernet/examples/CosmClient/CosmClient.ino        |  159 ++++++++++++++++++++
 .../examples/CosmClientString/CosmClientString.ino |  146 ++++++++++++++++++
 .../DhcpAddressPrinter/DhcpAddressPrinter.ino      |    8 +-
 .../examples/DhcpChatServer/DhcpChatServer.ino     |    9 +-
 Ethernet/examples/DnsWebClient/DnsWebClient.ino    |    9 +-
 Ethernet/examples/PachubeClient/PachubeClient.ino  |    9 +-
 .../PachubeClientString/PachubeClientString.ino    |   33 +++--
 Ethernet/examples/TelnetClient/TelnetClient.ino    |    8 +-
 Ethernet/examples/TwitterClient/TwitterClient.ino  |    8 +-
 Ethernet/examples/UdpNtpClient/UdpNtpClient.ino    |    7 +-
 Ethernet/examples/WebClient/WebClient.ino          |    7 +-
 .../WebClientRepeating/WebClientRepeating.ino      |  110 ++++++++++++++
 Ethernet/examples/WebServer/WebServer.ino          |    8 +-
 Ethernet/utility/w5100.h                           |    6 +-
 LiquidCrystal/examples/Autoscroll/Autoscroll.ino   |    3 +-
 LiquidCrystal/examples/Blink/Blink.ino             |    2 +-
 LiquidCrystal/examples/Cursor/Cursor.ino           |    3 +-
 LiquidCrystal/examples/Display/Display.ino         |    3 +-
 LiquidCrystal/examples/Scroll/Scroll.ino           |    3 +-
 .../examples/SerialDisplay/SerialDisplay.ino       |    2 +-
 .../examples/TextDirection/TextDirection.ino       |    3 +-
 LiquidCrystal/examples/setCursor/setCursor.ino     |    3 +-
 SD/examples/CardInfo/CardInfo.ino                  |    8 +-
 SD/examples/Datalogger/Datalogger.ino              |    8 +-
 SD/examples/DumpFile/DumpFile.ino                  |    9 +
 SD/examples/Files/Files.ino                        |    8 +-
 SD/examples/ReadWrite/ReadWrite.ino                |    8 +-
 SD/examples/listfiles/listfiles.ino                |    8 +-
 SPI/SPI.cpp                                        |   27 ++--
 Servo/Servo.cpp                                    |    2 +-
 .../SoftwareSerialExample.ino                      |   23 +++-
 .../examples/TwoPortReceive/TwoPortReceive.ino     |   25 +++-
 .../stepper_speedControl/stepper_speedControl.ino  |    5 +-
 36 files changed, 630 insertions(+), 65 deletions(-)
---
diff --git a/EEPROM/examples/eeprom_read/eeprom_read.ino b/EEPROM/examples/eeprom_read/eeprom_read.ino
index 88e3488..0709b2d 100644
--- a/EEPROM/examples/eeprom_read/eeprom_read.ino
+++ b/EEPROM/examples/eeprom_read/eeprom_read.ino
@@ -14,7 +14,11 @@ byte value;
 
 void setup()
 {
+  // initialize serial and wait for port to open:
   Serial.begin(9600);
+  while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
 }
 
 void loop()
diff --git a/Ethernet/EthernetClient.cpp b/Ethernet/EthernetClient.cpp
index a77a62b..9885efb 100644
--- a/Ethernet/EthernetClient.cpp
+++ b/Ethernet/EthernetClient.cpp
@@ -41,7 +41,7 @@ int EthernetClient::connect(IPAddress ip, uint16_t port) {
 
   for (int i = 0; i < MAX_SOCK_NUM; i++) {
     uint8_t s = W5100.readSnSR(i);
-    if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT) {
+    if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT || s == SnSR::CLOSE_WAIT) {
       _sock = i;
       break;
     }
diff --git a/Ethernet/examples/ChatServer/ChatServer.ino b/Ethernet/examples/ChatServer/ChatServer.ino
index de75257..d50e5a6 100644
--- a/Ethernet/examples/ChatServer/ChatServer.ino
+++ b/Ethernet/examples/ChatServer/ChatServer.ino
@@ -12,7 +12,7 @@
  
  created 18 Dec 2009
  by David A. Mellis
- modified 12 March 2012
+ modified 9 Apr 2012
  by Tom Igoe
  
  */
@@ -39,8 +39,13 @@ void setup() {
   Ethernet.begin(mac, ip, gateway, subnet);
   // start listening for clients
   server.begin();
-  // open the serial port
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   Serial.print("Chat server address:");
   Serial.println(Ethernet.localIP());
 }
diff --git a/Ethernet/examples/CosmClient/CosmClient.ino b/Ethernet/examples/CosmClient/CosmClient.ino
new file mode 100644
index 0000000..22815af
--- /dev/null
+++ b/Ethernet/examples/CosmClient/CosmClient.ino
@@ -0,0 +1,159 @@
+/*
+  Cosm sensor client
+ 
+ This sketch connects an analog sensor to Cosm (http://www.cosm.com)
+ using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
+ the Adafruit Ethernet shield, either one will work, as long as it's got
+ a Wiznet Ethernet module on board.
+ 
+ This example has been updated to use version 2.0 of the cosm.com API. 
+ To make it work, create a feed with a datastream, and give it the ID
+ sensor1. Or change the code below to match your feed.
+ 
+ 
+ Circuit:
+ * Analog sensor attached to analog in 0
+ * Ethernet shield attached to pins 10, 11, 12, 13
+ 
+ created 15 March 2010
+ updated 14 May 2012
+ by Tom Igoe with input from Usman Haque and Joe Saavedra
+ 
+http://arduino.cc/en/Tutorial/CosmClient
+ This code is in the public domain.
+ 
+ */
+
+#include <SPI.h>
+#include <Ethernet.h>
+
+#define APIKEY         "YOUR API KEY GOES HERE" // replace your Cosm api key here
+#define FEEDID         00000 // replace your feed ID
+#define USERAGENT      "My Project" // user agent is the project name
+
+// assign a MAC address for the ethernet controller.
+// Newer Ethernet shields have a MAC address printed on a sticker on the shield
+// fill in your address here:
+byte mac[] = { 
+  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
+
+// fill in an available IP address on your network here,
+// for manual configuration:
+IPAddress ip(10,0,1,20);
+
+// initialize the library instance:
+EthernetClient client;
+
+// if you don't want to use DNS (and reduce your sketch size)
+// use the numeric IP instead of the name for the server:
+//IPAddress server(216,52,233,121);      // numeric IP for api.cosm.com
+char server[] = "api.cosm.com";   // name address for cosm API
+
+unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
+boolean lastConnected = false;                 // state of the connection last time through the main loop
+const unsigned long postingInterval = 10*1000; //delay between updates to cosm.com
+
+void setup() {
+  // start serial port:
+  Serial.begin(9600);
+ // start the Ethernet connection:
+  if (Ethernet.begin(mac) == 0) {
+    Serial.println("Failed to configure Ethernet using DHCP");
+    // DHCP failed, so use a fixed IP address:
+    Ethernet.begin(mac, ip);
+  }
+}
+
+void loop() {
+  // read the analog sensor:
+  int sensorReading = analogRead(A0);   
+
+  // if there's incoming data from the net connection.
+  // send it out the serial port.  This is for debugging
+  // purposes only:
+  if (client.available()) {
+    char c = client.read();
+    Serial.print(c);
+  }
+
+  // if there's no net connection, but there was one last time
+  // through the loop, then stop the client:
+  if (!client.connected() && lastConnected) {
+    Serial.println();
+    Serial.println("disconnecting.");
+    client.stop();
+  }
+
+  // if you're not connected, and ten seconds have passed since
+  // your last connection, then connect again and send data:
+  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
+    sendData(sensorReading);
+  }
+  // store the state of the connection for next time through
+  // the loop:
+  lastConnected = client.connected();
+}
+
+// this method makes a HTTP connection to the server:
+void sendData(int thisData) {
+  // if there's a successful connection:
+  if (client.connect(server, 80)) {
+    Serial.println("connecting...");
+    // send the HTTP PUT request:
+    client.print("PUT /v2/feeds/");
+    client.print(FEEDID);
+    client.println(".csv HTTP/1.1");
+    client.println("Host: api.cosm.com");
+    client.print("X-ApiKey: ");
+    client.println(APIKEY);
+    client.print("User-Agent: ");
+    client.println(USERAGENT);
+    client.print("Content-Length: ");
+
+    // calculate the length of the sensor reading in bytes:
+    // 8 bytes for "sensor1," + number of digits of the data:
+    int thisLength = 8 + getLength(thisData);
+    client.println(thisLength);
+
+    // last pieces of the HTTP PUT request:
+    client.println("Content-Type: text/csv");
+    client.println("Connection: close");
+    client.println();
+
+    // here's the actual content of the PUT request:
+    client.print("sensor1,");
+    client.println(thisData);
+  
+  } 
+  else {
+    // if you couldn't make a connection:
+    Serial.println("connection failed");
+    Serial.println();
+    Serial.println("disconnecting.");
+    client.stop();
+  }
+   // note the time that the connection was made or attempted:
+  lastConnectionTime = millis();
+}
+
+
+// This method calculates the number of digits in the
+// sensor reading.  Since each digit of the ASCII decimal
+// representation is a byte, the number of digits equals
+// the number of bytes:
+
+int getLength(int someValue) {
+  // there's at least one byte:
+  int digits = 1;
+  // continually divide the value by ten, 
+  // adding one to the digit count for each
+  // time you divide, until you're at 0:
+  int dividend = someValue /10;
+  while (dividend > 0) {
+    dividend = dividend /10;
+    digits++;
+  }
+  // return the number of digits:
+  return digits;
+}
+
diff --git a/Ethernet/examples/CosmClientString/CosmClientString.ino b/Ethernet/examples/CosmClientString/CosmClientString.ino
new file mode 100644
index 0000000..05b549b
--- /dev/null
+++ b/Ethernet/examples/CosmClientString/CosmClientString.ino
@@ -0,0 +1,146 @@
+/*
+  Cosm sensor client with Strings
+ 
+ This sketch connects an analog sensor to Cosm (http://www.cosm.com)
+ using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
+ the Adafruit Ethernet shield, either one will work, as long as it's got
+ a Wiznet Ethernet module on board.
+ 
+ This example has been updated to use version 2.0 of the Cosm.com API. 
+ To make it work, create a feed with two datastreams, and give them the IDs
+ sensor1 and sensor2. Or change the code below to match your feed.
+ 
+ This example uses the String library, which is part of the Arduino core from
+ version 0019.  
+ 
+ Circuit:
+ * Analog sensor attached to analog in 0
+ * Ethernet shield attached to pins 10, 11, 12, 13
+ 
+ created 15 March 2010
+ updated 14 May 2012
+ by Tom Igoe with input from Usman Haque and Joe Saavedra
+ 
+ http://arduino.cc/en/Tutorial/CosmClientString
+ This code is in the public domain.
+ 
+ */
+
+#include <SPI.h>
+#include <Ethernet.h>
+
+
+#define APIKEY         "YOUR API KEY GOES HERE" // replace your Cosm api key here
+#define FEEDID         00000 // replace your feed ID
+#define USERAGENT      "My Project" // user agent is the project name
+
+// assign a MAC address for the ethernet controller.
+// fill in your address here:
+  byte mac[] = { 
+  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
+  
+// fill in an available IP address on your network here,
+// for manual configuration:
+IPAddress ip(10,0,1,20);
+
+// initialize the library instance:
+EthernetClient client;
+
+// if you don't want to use DNS (and reduce your sketch size)
+// use the numeric IP instead of the name for the server:
+//IPAddress server(216,52,233,121);      // numeric IP for api.cosm.com
+char server[] = "api.cosm.com";   // name address for Cosm API
+
+unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
+boolean lastConnected = false;                 // state of the connection last time through the main loop
+const unsigned long postingInterval = 10*1000;  //delay between updates to Cosm.com
+
+void setup() {
+  // start serial port:
+  Serial.begin(9600);
+  // give the ethernet module time to boot up:
+  delay(1000);
+  // start the Ethernet connection:
+  if (Ethernet.begin(mac) == 0) {
+    Serial.println("Failed to configure Ethernet using DHCP");
+    // DHCP failed, so use a fixed IP address:
+    Ethernet.begin(mac, ip);
+  }
+}
+
+void loop() {
+  // read the analog sensor:
+  int sensorReading = analogRead(A0);   
+  // convert the data to a String to send it:
+
+  String dataString = "sensor1,";
+  dataString += sensorReading;
+
+  // you can append multiple readings to this String if your
+  // Cosm feed is set up to handle multiple values:
+  int otherSensorReading = analogRead(A1);
+  dataString += "\nsensor2,";
+  dataString += otherSensorReading;
+
+  // if there's incoming data from the net connection.
+  // send it out the serial port.  This is for debugging
+  // purposes only:
+  if (client.available()) {
+    char c = client.read();
+    Serial.print(c);
+  }
+
+  // if there's no net connection, but there was one last time
+  // through the loop, then stop the client:
+  if (!client.connected() && lastConnected) {
+    Serial.println();
+    Serial.println("disconnecting.");
+    client.stop();
+  }
+
+  // if you're not connected, and ten seconds have passed since
+  // your last connection, then connect again and send data: 
+  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
+    sendData(dataString);
+  }
+  // store the state of the connection for next time through
+  // the loop:
+  lastConnected = client.connected();
+}
+
+// this method makes a HTTP connection to the server:
+void sendData(String thisData) {
+  // if there's a successful connection:
+  if (client.connect(server, 80)) {
+    Serial.println("connecting...");
+    // send the HTTP PUT request:
+    client.print("PUT /v2/feeds/");
+    client.print(FEEDID);
+    client.println(".csv HTTP/1.1");
+    client.println("Host: api.cosm.com");
+    client.print("X-ApiKey: ");
+    client.println(APIKEY);
+    client.print("User-Agent: ");
+    client.println(USERAGENT);
+    client.print("Content-Length: ");
+    client.println(thisData.length());
+
+    // last pieces of the HTTP PUT request:
+    client.println("Content-Type: text/csv");
+    client.println("Connection: close");
+    client.println();
+
+    // here's the actual content of the PUT request:
+    client.println(thisData);
+  } 
+  else {
+    // if you couldn't make a connection:
+    Serial.println("connection failed");
+    Serial.println();
+    Serial.println("disconnecting.");
+    client.stop();
+  }
+  // note the time that the connection was made or attempted:
+  lastConnectionTime = millis();
+}
+
diff --git a/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino b/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino
index 630dd17..5eaaf24 100644
--- a/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino
+++ b/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino
@@ -9,6 +9,7 @@
  * Ethernet shield attached to pins 10, 11, 12, 13
  
  created 12 April 2011
+ modified 9 Apr 2012
  by Tom Igoe
  
  */
@@ -27,8 +28,13 @@ byte mac[] = {
 EthernetClient client;
 
 void setup() {
-  // start the serial library:
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+  // this check is only needed on the Leonardo:
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
   // start the Ethernet connection:
   if (Ethernet.begin(mac) == 0) {
     Serial.println("Failed to configure Ethernet using DHCP");
diff --git a/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino b/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino
index 5082054..09cbd43 100644
--- a/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino
+++ b/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino
@@ -12,6 +12,7 @@
  * Ethernet shield attached to pins 10, 11, 12, 13
  
  created 21 May 2011
+ modified 9 Apr 2012
  by Tom Igoe
  Based on ChatServer example by David A. Mellis
  
@@ -34,8 +35,14 @@ EthernetServer server(23);
 boolean gotAMessage = false; // whether or not you got a message from the client yet
 
 void setup() {
-   // open the serial port
+  // Open serial communications and wait for port to open:
   Serial.begin(9600);
+  // this check is only needed on the Leonardo:
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   // start the Ethernet connection:
   Serial.println("Trying to get an IP address using DHCP");
   if (Ethernet.begin(mac) == 0) {
diff --git a/Ethernet/examples/DnsWebClient/DnsWebClient.ino b/Ethernet/examples/DnsWebClient/DnsWebClient.ino
index 5c7a53a..c14abf4 100644
--- a/Ethernet/examples/DnsWebClient/DnsWebClient.ino
+++ b/Ethernet/examples/DnsWebClient/DnsWebClient.ino
@@ -9,7 +9,7 @@
  
  created 18 Dec 2009
  by David A. Mellis
- modified 12 April 2011
+ modified 9 Apr 2012
  by Tom Igoe, based on work by Adrian McEwen
  
  */
@@ -28,8 +28,13 @@ char serverName[] = "www.google.com";
 EthernetClient client;
 
 void setup() {
-  // start the serial library:
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   // start the Ethernet connection:
   if (Ethernet.begin(mac) == 0) {
     Serial.println("Failed to configure Ethernet using DHCP");
diff --git a/Ethernet/examples/PachubeClient/PachubeClient.ino b/Ethernet/examples/PachubeClient/PachubeClient.ino
index 4d4290d..dfd2d40 100644
--- a/Ethernet/examples/PachubeClient/PachubeClient.ino
+++ b/Ethernet/examples/PachubeClient/PachubeClient.ino
@@ -16,7 +16,7 @@
  * Ethernet shield attached to pins 10, 11, 12, 13
  
  created 15 March 2010
- updated 16 Mar 2012
+ modified 9 Apr 2012
  by Tom Igoe with input from Usman Haque and Joe Saavedra
  
 http://arduino.cc/en/Tutorial/PachubeClient
@@ -53,8 +53,13 @@ boolean lastConnected = false;                 // state of the connection last t
 const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
 
 void setup() {
-  // start serial port:
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
  // start the Ethernet connection:
   if (Ethernet.begin(mac) == 0) {
     Serial.println("Failed to configure Ethernet using DHCP");
diff --git a/Ethernet/examples/PachubeClientString/PachubeClientString.ino b/Ethernet/examples/PachubeClientString/PachubeClientString.ino
index 3535287..2a96e9f 100644
--- a/Ethernet/examples/PachubeClientString/PachubeClientString.ino
+++ b/Ethernet/examples/PachubeClientString/PachubeClientString.ino
@@ -1,12 +1,12 @@
 /*
-  Pachube sensor client with Strings
+  Cosm sensor client with Strings
  
- This sketch connects an analog sensor to Pachube (http://www.pachube.com)
+ This sketch connects an analog sensor to Cosm (http://www.cosm.com)
  using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
  the Adafruit Ethernet shield, either one will work, as long as it's got
  a Wiznet Ethernet module on board.
  
- This example has been updated to use version 2.0 of the Pachube.com API. 
+ This example has been updated to use version 2.0 of the Cosm.com API. 
  To make it work, create a feed with two datastreams, and give them the IDs
  sensor1 and sensor2. Or change the code below to match your feed.
  
@@ -18,10 +18,10 @@
  * Ethernet shield attached to pins 10, 11, 12, 13
  
  created 15 March 2010
- updated 16 Mar 2012
+ modified 9 Apr 2012
  by Tom Igoe with input from Usman Haque and Joe Saavedra
  
- http://arduino.cc/en/Tutorial/PachubeClientString
+ http://arduino.cc/en/Tutorial/CosmClientString
  This code is in the public domain.
  
  */
@@ -30,14 +30,16 @@
 #include <Ethernet.h>
 
 
-#define APIKEY         "YOUR API KEY GOES HERE" // replace your pachube api key here
+/#define APIKEY         "YOUR API KEY GOES HERE" // replace your Cosm api key here
 #define FEEDID         00000 // replace your feed ID
 #define USERAGENT      "My Project" // user agent is the project name
 
+
 // assign a MAC address for the ethernet controller.
 // fill in your address here:
   byte mac[] = { 
   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
+
 // fill in an available IP address on your network here,
 // for manual configuration:
 IPAddress ip(10,0,1,20);
@@ -47,16 +49,21 @@ EthernetClient client;
 
 // if you don't want to use DNS (and reduce your sketch size)
 // use the numeric IP instead of the name for the server:
-//IPAddress server(216,52,233,122);      // numeric IP for api.pachube.com
-char server[] = "api.pachube.com";   // name address for pachube API
+IPAddress server(216,52,233,121);      // numeric IP for api.cosm.com
+//char server[] = "api.cosm.com";   // name address for Cosm API
 
 unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
 boolean lastConnected = false;                 // state of the connection last time through the main loop
-const unsigned long postingInterval = 10*1000;  //delay between updates to Pachube.com
+const unsigned long postingInterval = 10*1000;  //delay between updates to Cosm.com
 
 void setup() {
-  // start serial port:
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+  while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   // give the ethernet module time to boot up:
   delay(1000);
   // start the Ethernet connection:
@@ -76,7 +83,7 @@ void loop() {
   dataString += sensorReading;
 
   // you can append multiple readings to this String if your
-  // pachube feed is set up to handle multiple values:
+  // Cosm feed is set up to handle multiple values:
   int otherSensorReading = analogRead(A1);
   dataString += "\nsensor2,";
   dataString += otherSensorReading;
@@ -116,8 +123,8 @@ void sendData(String thisData) {
     client.print("PUT /v2/feeds/");
     client.print(FEEDID);
     client.println(".csv HTTP/1.1");
-    client.println("Host: api.pachube.com");
-    client.print("X-PachubeApiKey: ");
+    client.println("Host: api.cosm.com");
+    client.print("X-CosmApiKey: ");
     client.println(APIKEY);
     client.print("User-Agent: ");
     client.println(USERAGENT);
diff --git a/Ethernet/examples/TelnetClient/TelnetClient.ino b/Ethernet/examples/TelnetClient/TelnetClient.ino
index 5cf1ad8..3457125 100644
--- a/Ethernet/examples/TelnetClient/TelnetClient.ino
+++ b/Ethernet/examples/TelnetClient/TelnetClient.ino
@@ -13,6 +13,7 @@
  * Ethernet shield attached to pins 10, 11, 12, 13
  
  created 14 Sep 2010
+ modified 9 Apr 2012
  by Tom Igoe
  
  */
@@ -38,8 +39,13 @@ EthernetClient client;
 void setup() {
   // start the Ethernet connection:
   Ethernet.begin(mac, ip);
-  // start the serial library:
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   // give the Ethernet shield a second to initialize:
   delay(1000);
   Serial.println("connecting...");
diff --git a/Ethernet/examples/TwitterClient/TwitterClient.ino b/Ethernet/examples/TwitterClient/TwitterClient.ino
index a3b397d..3587d72 100644
--- a/Ethernet/examples/TwitterClient/TwitterClient.ino
+++ b/Ethernet/examples/TwitterClient/TwitterClient.ino
@@ -17,6 +17,7 @@
  * Ethernet shield attached to pins 10, 11, 12, 13
  
  created 21 May 2011
+ modified 9 Apr 2012
  by Tom Igoe
  
  This code is in the public domain.
@@ -51,8 +52,13 @@ void setup() {
   currentLine.reserve(256);
   tweet.reserve(150);
 
-  // initialize serial:
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   // attempt a DHCP connection:
   Serial.println("Attempting to get an IP address using DHCP:");
   if (!Ethernet.begin(mac)) {
diff --git a/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino b/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
index b4e24b8..93ffe39 100644
--- a/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
+++ b/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
@@ -9,7 +9,7 @@
  
  created 4 Sep 2010 
  by Michael Margolis
- modified 17 Sep 2010
+ modified 9 Apr 2012
  by Tom Igoe
  
  This code is in the public domain.
@@ -38,7 +38,12 @@ EthernetUDP Udp;
 
 void setup() 
 {
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
 
   // start Ethernet and UDP
   if (Ethernet.begin(mac) == 0) {
diff --git a/Ethernet/examples/WebClient/WebClient.ino b/Ethernet/examples/WebClient/WebClient.ino
index 1806854..5d5d7f2 100644
--- a/Ethernet/examples/WebClient/WebClient.ino
+++ b/Ethernet/examples/WebClient/WebClient.ino
@@ -8,6 +8,7 @@
  * Ethernet shield attached to pins 10, 11, 12, 13
  
  created 18 Dec 2009
+ modified 9 Apr 2012
  by David A. Mellis
  
  */
@@ -26,8 +27,12 @@ IPAddress server(173,194,33,104); // Google
 EthernetClient client;
 
 void setup() {
-  // start the serial library:
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
   // start the Ethernet connection:
   if (Ethernet.begin(mac) == 0) {
     Serial.println("Failed to configure Ethernet using DHCP");
diff --git a/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino b/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino
new file mode 100644
index 0000000..e0f06c4
--- /dev/null
+++ b/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino
@@ -0,0 +1,110 @@
+/*
+  Repeating Web client
+ 
+ This sketch connects to a a web server and makes a request
+ using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
+ the Adafruit Ethernet shield, either one will work, as long as it's got
+ a Wiznet Ethernet module on board.
+ 
+ This example uses DNS, by assigning the Ethernet client with a MAC address,
+ IP address, and DNS address.
+ 
+ Circuit:
+ * Ethernet shield attached to pins 10, 11, 12, 13
+ 
+ created 19 Apr 2012
+ by Tom Igoe
+ 
+ http://arduino.cc/en/Tutorial/WebClientRepeating
+ This code is in the public domain.
+ 
+ */
+
+#include <SPI.h>
+#include <Ethernet.h>
+
+// assign a MAC address for the ethernet controller.
+// fill in your address here:
+byte mac[] = { 
+  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
+// fill in an available IP address on your network here,
+// for manual configuration:
+IPAddress ip(10,0,0,20);
+
+// fill in your Domain Name Server address here:
+IPAddress myDns(1,1,1,1);
+
+// initialize the library instance:
+EthernetClient client;
+
+char server[] = "www.arduino.cc";
+
+unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
+boolean lastConnected = false;                 // state of the connection last time through the main loop
+const unsigned long postingInterval = 60*1000;  // delay between updates, in milliseconds
+
+void setup() {
+  // start serial port:
+  Serial.begin(9600);
+  // give the ethernet module time to boot up:
+  delay(1000);
+  // start the Ethernet connection using a fixed IP address and DNS server:
+  Ethernet.begin(mac, ip, myDns);
+  // print the Ethernet board/shield's IP address:
+  Serial.print("My IP address: ");
+  Serial.println(Ethernet.localIP());
+}
+
+void loop() {
+  // if there's incoming data from the net connection.
+  // send it out the serial port.  This is for debugging
+  // purposes only:
+  if (client.available()) {
+    char c = client.read();
+    Serial.print(c);
+  }
+
+  // if there's no net connection, but there was one last time
+  // through the loop, then stop the client:
+  if (!client.connected() && lastConnected) {
+    Serial.println();
+    Serial.println("disconnecting.");
+    client.stop();
+  }
+
+  // if you're not connected, and ten seconds have passed since
+  // your last connection, then connect again and send data:
+  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
+    httpRequest();
+  }
+  // store the state of the connection for next time through
+  // the loop:
+  lastConnected = client.connected();
+}
+
+// this method makes a HTTP connection to the server:
+void httpRequest() {
+  // if there's a successful connection:
+  if (client.connect(server, 80)) {
+    Serial.println("connecting...");
+    // send the HTTP PUT request:
+    client.println("GET /latest.txt HTTP/1.1");
+    client.println("Host: www.arduino.cc");
+    client.println("User-Agent: arduino-ethernet");
+    client.println("Connection: close");
+    client.println();
+
+    // note the time that the connection was made:
+    lastConnectionTime = millis();
+  } 
+  else {
+    // if you couldn't make a connection:
+    Serial.println("connection failed");
+    Serial.println("disconnecting.");
+    client.stop();
+  }
+}
+
+
+
+
diff --git a/Ethernet/examples/WebServer/WebServer.ino b/Ethernet/examples/WebServer/WebServer.ino
index 7cf2c53..ce8dbb1 100644
--- a/Ethernet/examples/WebServer/WebServer.ino
+++ b/Ethernet/examples/WebServer/WebServer.ino
@@ -10,7 +10,7 @@
  
  created 18 Dec 2009
  by David A. Mellis
- modified 20 Mar 2012
+ modified 9 Apr 2012
  by Tom Igoe
  
  */
@@ -30,7 +30,13 @@ IPAddress ip(192,168,1, 177);
 EthernetServer server(80);
 
 void setup() {
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   // start the Ethernet connection and the server:
   Ethernet.begin(mac, ip);
   server.begin();
diff --git a/Ethernet/utility/w5100.h b/Ethernet/utility/w5100.h
index 153aedb..8dccd9f 100755
--- a/Ethernet/utility/w5100.h
+++ b/Ethernet/utility/w5100.h
@@ -327,7 +327,11 @@ private:
   inline static void initSS()    { DDRB  |=  _BV(4); };
   inline static void setSS()     { PORTB &= ~_BV(4); };
   inline static void resetSS()   { PORTB |=  _BV(4); };
-#elif defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__)
+#elif defined(__AVR_ATmega32U4__)
+  inline static void initSS()    { DDRB  |=  _BV(6); };
+  inline static void setSS()     { PORTB &= ~_BV(6); };
+  inline static void resetSS()   { PORTB |=  _BV(6); }; 
+#elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__)
   inline static void initSS()    { DDRB  |=  _BV(0); };
   inline static void setSS()     { PORTB &= ~_BV(0); };
   inline static void resetSS()   { PORTB |=  _BV(0); }; 
diff --git a/LiquidCrystal/examples/Autoscroll/Autoscroll.ino b/LiquidCrystal/examples/Autoscroll/Autoscroll.ino
index 27123ad..1127d8f 100644
--- a/LiquidCrystal/examples/Autoscroll/Autoscroll.ino
+++ b/LiquidCrystal/examples/Autoscroll/Autoscroll.ino
@@ -32,7 +32,8 @@
  
  This example code is in the public domain.
 
- http://www.arduino.cc/en/Tutorial/LiquidCrystal
+ http://arduino.cc/en/Tutorial/LiquidCrystalAutoscroll
+
  */
 
 // include the library code:
diff --git a/LiquidCrystal/examples/Blink/Blink.ino b/LiquidCrystal/examples/Blink/Blink.ino
index e410424..9667b5d 100644
--- a/LiquidCrystal/examples/Blink/Blink.ino
+++ b/LiquidCrystal/examples/Blink/Blink.ino
@@ -32,7 +32,7 @@
  
  This example code is in the public domain.
 
- http://www.arduino.cc/en/Tutorial/LiquidCrystal
+ http://arduino.cc/en/Tutorial/LiquidCrystalBlink
  
  */
 
diff --git a/LiquidCrystal/examples/Cursor/Cursor.ino b/LiquidCrystal/examples/Cursor/Cursor.ino
index 28e2a6a..05862a4 100644
--- a/LiquidCrystal/examples/Cursor/Cursor.ino
+++ b/LiquidCrystal/examples/Cursor/Cursor.ino
@@ -33,7 +33,8 @@
 
  This example code is in the public domain.
 
- http://www.arduino.cc/en/Tutorial/LiquidCrystal
+ http://arduino.cc/en/Tutorial/LiquidCrystalCursor
+
  */
 
 // include the library code:
diff --git a/LiquidCrystal/examples/Display/Display.ino b/LiquidCrystal/examples/Display/Display.ino
index b000731..a85effb 100644
--- a/LiquidCrystal/examples/Display/Display.ino
+++ b/LiquidCrystal/examples/Display/Display.ino
@@ -33,7 +33,8 @@
 
  This example code is in the public domain.
 
- http://www.arduino.cc/en/Tutorial/LiquidCrystal
+ http://arduino.cc/en/Tutorial/LiquidCrystalDisplay
+
  */
 
 // include the library code:
diff --git a/LiquidCrystal/examples/Scroll/Scroll.ino b/LiquidCrystal/examples/Scroll/Scroll.ino
index 71e5e8c..0d6d8dc 100644
--- a/LiquidCrystal/examples/Scroll/Scroll.ino
+++ b/LiquidCrystal/examples/Scroll/Scroll.ino
@@ -33,7 +33,8 @@
  
  This example code is in the public domain.
  
- http://www.arduino.cc/en/Tutorial/LiquidCrystal
+ http://arduino.cc/en/Tutorial/LiquidCrystalScroll
+
  */
 
 // include the library code:
diff --git a/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino b/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino
index 9727cee..a6f8f40 100644
--- a/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino
+++ b/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino
@@ -32,7 +32,7 @@
  
  This example code is in the public domain.
  
- http://www.arduino.cc/en/Tutorial/LiquidCrystal
+ http://arduino.cc/en/Tutorial/LiquidCrystalSerial
  */
 
 // include the library code:
diff --git a/LiquidCrystal/examples/TextDirection/TextDirection.ino b/LiquidCrystal/examples/TextDirection/TextDirection.ino
index 51bab1f..cabd8ea 100644
--- a/LiquidCrystal/examples/TextDirection/TextDirection.ino
+++ b/LiquidCrystal/examples/TextDirection/TextDirection.ino
@@ -32,7 +32,7 @@
  
  This example code is in the public domain.
  
- http://www.arduino.cc/en/Tutorial/LiquidCrystal
+ http://arduino.cc/en/Tutorial/LiquidCrystalTextDirection
  
  */
 
@@ -49,7 +49,6 @@ void setup() {
   lcd.begin(16, 2);
   // turn on the cursor:
   lcd.cursor();
-  Serial.begin(9600);
 }
 
 void loop() {
diff --git a/LiquidCrystal/examples/setCursor/setCursor.ino b/LiquidCrystal/examples/setCursor/setCursor.ino
index 3c4edf3..e45c491 100644
--- a/LiquidCrystal/examples/setCursor/setCursor.ino
+++ b/LiquidCrystal/examples/setCursor/setCursor.ino
@@ -32,7 +32,8 @@
  
  This example code is in the public domain.
  
- http://www.arduino.cc/en/Tutorial/LiquidCrystal
+ http://arduino.cc/en/Tutorial/LiquidCrystalSetCursor
+
  */
 
 // include the library code:
diff --git a/SD/examples/CardInfo/CardInfo.ino b/SD/examples/CardInfo/CardInfo.ino
index fb2f6c3..0c2dfc5 100644
--- a/SD/examples/CardInfo/CardInfo.ino
+++ b/SD/examples/CardInfo/CardInfo.ino
@@ -16,7 +16,7 @@
  
  created  28 Mar 2011
  by Limor Fried 
- modified 16 Mar 2011
+ modified 9 Apr 2012
  by Tom Igoe
  */
  // include the SD library:
@@ -35,7 +35,13 @@ const int chipSelect = 4;
 
 void setup()
 {
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   Serial.print("\nInitializing SD card...");
   // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
   // Note that even if it's not used as the CS pin, the hardware SS pin 
diff --git a/SD/examples/Datalogger/Datalogger.ino b/SD/examples/Datalogger/Datalogger.ino
index 73d81af..a7f85ee 100644
--- a/SD/examples/Datalogger/Datalogger.ino
+++ b/SD/examples/Datalogger/Datalogger.ino
@@ -13,7 +13,7 @@
  ** CS - pin 4
  
  created  24 Nov 2010
- updated 2 Dec 2010
+ modified 9 Apr 2012
  by Tom Igoe
  
  This example code is in the public domain.
@@ -30,7 +30,13 @@ const int chipSelect = 4;
 
 void setup()
 {
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   Serial.print("Initializing SD card...");
   // make sure that the default chip select pin is set to
   // output, even if you don't use it:
diff --git a/SD/examples/DumpFile/DumpFile.ino b/SD/examples/DumpFile/DumpFile.ino
index 961717f..d83089a 100644
--- a/SD/examples/DumpFile/DumpFile.ino
+++ b/SD/examples/DumpFile/DumpFile.ino
@@ -12,6 +12,9 @@
  ** CS - pin 4
  
  created  22 December 2010
+ by Limor Fried
+ modified 9 Apr 2012
+ by Tom Igoe
  
  This example code is in the public domain.
  	 
@@ -27,7 +30,13 @@ const int chipSelect = 4;
 
 void setup()
 {
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   Serial.print("Initializing SD card...");
   // make sure that the default chip select pin is set to
   // output, even if you don't use it:
diff --git a/SD/examples/Files/Files.ino b/SD/examples/Files/Files.ino
index 5ed9fea..a15b862 100644
--- a/SD/examples/Files/Files.ino
+++ b/SD/examples/Files/Files.ino
@@ -11,7 +11,7 @@
  
  created   Nov 2010
  by David A. Mellis
- updated 2 Dec 2010
+ modified 9 Apr 2012
  by Tom Igoe
  
  This example code is in the public domain.
@@ -23,7 +23,13 @@ File myFile;
 
 void setup()
 {
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   Serial.print("Initializing SD card...");
   // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
   // Note that even if it's not used as the CS pin, the hardware SS pin 
diff --git a/SD/examples/ReadWrite/ReadWrite.ino b/SD/examples/ReadWrite/ReadWrite.ino
index 9957218..5805fc8 100644
--- a/SD/examples/ReadWrite/ReadWrite.ino
+++ b/SD/examples/ReadWrite/ReadWrite.ino
@@ -11,7 +11,7 @@
  
  created   Nov 2010
  by David A. Mellis
- updated 2 Dec 2010
+ modified 9 Apr 2012
  by Tom Igoe
  
  This example code is in the public domain.
@@ -24,7 +24,13 @@ File myFile;
 
 void setup()
 {
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   Serial.print("Initializing SD card...");
   // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
   // Note that even if it's not used as the CS pin, the hardware SS pin 
diff --git a/SD/examples/listfiles/listfiles.ino b/SD/examples/listfiles/listfiles.ino
index b2435a2..876c3f8 100644
--- a/SD/examples/listfiles/listfiles.ino
+++ b/SD/examples/listfiles/listfiles.ino
@@ -11,7 +11,7 @@
  
  created   Nov 2010
  by David A. Mellis
- updated 2 Dec 2010
+ modified 9 Apr 2012
  by Tom Igoe
  
  This example code is in the public domain.
@@ -23,7 +23,13 @@ File root;
 
 void setup()
 {
+  // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   Serial.print("Initializing SD card...");
   // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
   // Note that even if it's not used as the CS pin, the hardware SS pin 
diff --git a/SPI/SPI.cpp b/SPI/SPI.cpp
index 42915df..5e48073 100644
--- a/SPI/SPI.cpp
+++ b/SPI/SPI.cpp
@@ -14,27 +14,32 @@
 SPIClass SPI;
 
 void SPIClass::begin() {
-  // Set direction register for SCK and MOSI pin.
-  // MISO pin automatically overrides to INPUT.
+
+  // Set SS to high so a connected chip will be "deselected" by default
+  digitalWrite(SS, HIGH);
+
   // When the SS pin is set as OUTPUT, it can be used as
   // a general purpose output port (it doesn't influence
   // SPI operations).
-
-  pinMode(SCK, OUTPUT);
-  pinMode(MOSI, OUTPUT);
   pinMode(SS, OUTPUT);
-  
-  digitalWrite(SCK, LOW);
-  digitalWrite(MOSI, LOW);
-  digitalWrite(SS, HIGH);
 
-  // Warning: if the SS pin ever becomes a LOW INPUT then SPI 
-  // automatically switches to Slave, so the data direction of 
+  // Warning: if the SS pin ever becomes a LOW INPUT then SPI
+  // automatically switches to Slave, so the data direction of
   // the SS pin MUST be kept as OUTPUT.
   SPCR |= _BV(MSTR);
   SPCR |= _BV(SPE);
+
+  // Set direction register for SCK and MOSI pin.
+  // MISO pin automatically overrides to INPUT.
+  // By doing this AFTER enabling SPI, we avoid accidentally
+  // clocking in a single bit since the lines go directly
+  // from "input" to SPI control.  
+  // http://code.google.com/p/arduino/issues/detail?id=888
+  pinMode(SCK, OUTPUT);
+  pinMode(MOSI, OUTPUT);
 }
 
+
 void SPIClass::end() {
   SPCR &= ~_BV(SPE);
 }
diff --git a/Servo/Servo.cpp b/Servo/Servo.cpp
index dbe3bed..a716433 100755
--- a/Servo/Servo.cpp
+++ b/Servo/Servo.cpp
@@ -89,7 +89,7 @@ static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t
   }  
   else { 
     // finished all channels so wait for the refresh period to expire before starting over 
-    if( (unsigned)*TCNTn <  (usToTicks(REFRESH_INTERVAL) + 4) )  // allow a few ticks to ensure the next OCR1A not missed
+    if( ((unsigned)*TCNTn) + 4 < usToTicks(REFRESH_INTERVAL) )  // allow a few ticks to ensure the next OCR1A not missed
       *OCRnA = (unsigned int)usToTicks(REFRESH_INTERVAL);  
     else 
       *OCRnA = *TCNTn + 4;  // at least REFRESH_INTERVAL has elapsed
diff --git a/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino b/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino
index 615d2b3..6101bb1 100644
--- a/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino
+++ b/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino
@@ -5,10 +5,20 @@
  Receives from software serial, sends to hardware serial.
  
  The circuit: 
- * RX is digital pin 2 (connect to TX of other device)
- * TX is digital pin 3 (connect to RX of other device)
+ * RX is digital pin 10 (connect to TX of other device)
+ * TX is digital pin 11 (connect to RX of other device)
+ 
+ Note:
+ Not all pins on the Mega and Mega 2560 support change interrupts, 
+ so only the following can be used for RX: 
+ 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
+ 
+ Not all pins on the Leonardo support change interrupts, 
+ so only the following can be used for RX: 
+ 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
  
  created back in the mists of time
+ modified 25 May 2012
  by Tom Igoe
  based on Mikal Hart's example
  
@@ -17,11 +27,17 @@
  */
 #include <SoftwareSerial.h>
 
-SoftwareSerial mySerial(2, 3); // RX, TX
+SoftwareSerial mySerial(10, 11); // RX, TX
 
 void setup()  
 {
+  // Open serial communications and wait for port to open:
   Serial.begin(57600);
+  while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+
   Serial.println("Goodnight moon!");
 
   // set the data rate for the SoftwareSerial port
@@ -36,3 +52,4 @@ void loop() // run over and over
   if (Serial.available())
     mySerial.write(Serial.read());
 }
+
diff --git a/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino b/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino
index e870c6f..d607ee6 100644
--- a/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino
+++ b/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino
@@ -16,7 +16,17 @@
  * First serial device's TX attached to digital pin 2, RX to pin 3
  * Second serial device's TX attached to digital pin 4, RX to pin 5
  
+ Note:
+ Not all pins on the Mega and Mega 2560 support change interrupts, 
+ so only the following can be used for RX: 
+ 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
+ 
+ Not all pins on the Leonardo support change interrupts, 
+ so only the following can be used for RX: 
+ 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
+ 
  created 18 Apr. 2011
+ modified 25 May 2012
  by Tom Igoe
  based on Mikal Hart's twoPortRXExample
  
@@ -25,16 +35,21 @@
  */
 
 #include <SoftwareSerial.h>
-// software serial #1: TX = digital pin 2, RX = digital pin 3
-SoftwareSerial portOne(2, 3);
+// software serial #1: TX = digital pin 10, RX = digital pin 11
+SoftwareSerial portOne(10,11);
 
-// software serial #2: TX = digital pin 4, RX = digital pin 5
-SoftwareSerial portTwo(4, 5);
+// software serial #2: TX = digital pin 8, RX = digital pin 9
+// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega
+SoftwareSerial portTwo(8,9);
 
 void setup()
 {
-  // Start the hardware serial port
+ // Open serial communications and wait for port to open:
   Serial.begin(9600);
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
 
   // Start each software serial port
   portOne.begin(9600);
diff --git a/Stepper/examples/stepper_speedControl/stepper_speedControl.ino b/Stepper/examples/stepper_speedControl/stepper_speedControl.ino
index dbd0f7f..1a67a55 100644
--- a/Stepper/examples/stepper_speedControl/stepper_speedControl.ino
+++ b/Stepper/examples/stepper_speedControl/stepper_speedControl.ino
@@ -26,11 +26,10 @@ const int stepsPerRevolution = 200;  // change this to fit the number of steps p
 // initialize the stepper library on pins 8 through 11:
 Stepper myStepper(stepsPerRevolution, 8,9,10,11);            
 
-int stepCount = 0;         // number of steps the motor has taken
+int stepCount = 0;  // number of steps the motor has taken
 
 void setup() {
-  // initialize the serial port:
-  Serial.begin(9600);
+  // nothing to do inside the setup
 }
 
 void loop() {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]