[gnoduino] arduino: update libraries to git master sdk (pre 1.0.6)



commit 013d2606c255431d29ee82b913f0fe81e3be93d9
Author: Pascal de Bruijn <pmjdebruijn pcode nl>
Date:   Thu Jul 17 18:22:48 2014 +0200

    arduino: update libraries to git master sdk (pre 1.0.6)

 libraries/Ethernet/EthernetClient.cpp              |    4 +
 libraries/Ethernet/EthernetClient.h                |    2 +
 .../AdvancedChatServer/AdvancedChatServer.ino      |  108 +++++++++++++++
 .../BarometricPressureWebServer.ino                |  103 +++++++-------
 .../examples/TwitterClient/TwitterClient.ino       |  136 -------------------
 .../examples/UdpNtpClient/UdpNtpClient.ino         |   49 ++++----
 .../XivelyClient.ino}                              |   45 +++----
 .../XivelyClientString.ino}                        |   47 ++++----
 .../Firmata/examples/I2CFirmata/I2CFirmata.ino     |   32 +++---
 .../examples/CustomCharacter/CustomCharacter.ino   |  140 ++++++++++++++++++++
 .../examples/HelloWorld/HelloWorld.ino             |    2 +
 libraries/SD/examples/listfiles/listfiles.ino      |   12 +-
 .../BarometricPressureSensor.ino                   |   94 +++++++-------
 .../BarometricPressureSensor.ino                   |  140 ++++++++++++++++++++
 libraries/Servo/examples/Knob/Knob.ino             |   12 ++-
 libraries/Servo/examples/Sweep/Sweep.ino           |   17 ++-
 libraries/SoftwareSerial/SoftwareSerial.cpp        |   14 +-
 libraries/SoftwareSerial/keywords.txt              |    7 +-
 18 files changed, 620 insertions(+), 344 deletions(-)
---
diff --git a/libraries/Ethernet/EthernetClient.cpp b/libraries/Ethernet/EthernetClient.cpp
index 9885efb..ef3d19b 100644
--- a/libraries/Ethernet/EthernetClient.cpp
+++ b/libraries/Ethernet/EthernetClient.cpp
@@ -163,3 +163,7 @@ uint8_t EthernetClient::status() {
 EthernetClient::operator bool() {
   return _sock != MAX_SOCK_NUM;
 }
+
+bool EthernetClient::operator==(const EthernetClient& rhs) {
+  return _sock == rhs._sock && _sock != MAX_SOCK_NUM && rhs._sock != MAX_SOCK_NUM;
+}
diff --git a/libraries/Ethernet/EthernetClient.h b/libraries/Ethernet/EthernetClient.h
index 44740fe..1992db0 100644
--- a/libraries/Ethernet/EthernetClient.h
+++ b/libraries/Ethernet/EthernetClient.h
@@ -24,6 +24,8 @@ public:
   virtual void stop();
   virtual uint8_t connected();
   virtual operator bool();
+  virtual bool operator==(const EthernetClient&);
+  virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); };
 
   friend class EthernetServer;
   
diff --git a/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino 
b/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino
new file mode 100644
index 0000000..8a57997
--- /dev/null
+++ b/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino
@@ -0,0 +1,108 @@
+/*
+ Advanced Chat Server
+
+ A more advanced server that distributes any incoming messages
+ to all connected clients but the client the message comes from.
+ To use telnet to  your device's IP address and type.
+ You can see the client's input in the serial monitor as well.
+ Using an Arduino Wiznet Ethernet shield.
+
+ Circuit:
+ * Ethernet shield attached to pins 10, 11, 12, 13
+ * Analog inputs attached to pins A0 through A5 (optional)
+
+ created 18 Dec 2009
+ by David A. Mellis
+ modified 9 Apr 2012
+ by Tom Igoe
+ redesigned to make use of operator== 25 Nov 2013
+ by Norbert Truchsess
+
+ */
+
+#include <SPI.h>
+#include <Ethernet.h>
+
+// Enter a MAC address and IP address for your controller below.
+// The IP address will be dependent on your local network.
+// gateway and subnet are optional:
+byte mac[] = {
+  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+IPAddress ip(192,168,1, 177);
+IPAddress gateway(192,168,1, 1);
+IPAddress subnet(255, 255, 0, 0);
+
+
+// telnet defaults to port 23
+EthernetServer server(23);
+
+EthernetClient clients[4];
+
+void setup() {
+  // initialize the ethernet device
+  Ethernet.begin(mac, ip, gateway, subnet);
+  // start listening for clients
+  server.begin();
+ // 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());
+}
+
+void loop() {
+  // wait for a new client:
+  EthernetClient client = server.available();
+
+  // when the client sends the first byte, say hello:
+  if (client) {
+
+    boolean newClient = true;
+    for (byte i=0;i<4;i++) {
+      //check whether this client refers to the same socket as one of the existing instances:
+      if (clients[i]==client) {
+        newClient = false;
+        break;
+      }
+    }
+
+    if (newClient) {
+      //check which of the existing clients can be overridden:
+      for (byte i=0;i<4;i++) {
+        if (!clients[i] && clients[i]!=client) {
+          clients[i] = client;
+          // clead out the input buffer:
+          client.flush();
+          Serial.println("We have a new client");
+          client.print("Hello, client number: ");
+          client.print(i);
+          client.println();
+          break;
+        }
+      }
+    }
+
+    if (client.available() > 0) {
+      // read the bytes incoming from the client:
+      char thisChar = client.read();
+      // echo the bytes back to all other connected clients:
+      for (byte i=0;i<4;i++) {
+        if (clients[i] && (clients[i]!=client)) {
+          clients[i].write(thisChar);
+        }
+      }
+      // echo the bytes to the server as well:
+      Serial.write(thisChar);
+    }
+  }
+  for (byte i=0;i<4;i++) {
+    if (!(clients[i].connected())) {
+      // client.stop() invalidates the internal socket-descriptor, so next use of == will allways return 
false;
+      clients[i].stop();
+    }
+  }
+}
diff --git a/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino 
b/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino
index e21df23..81cc89a 100644
--- a/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino
+++ b/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino
@@ -56,57 +56,6 @@ float temperature = 0.0;
 long pressure = 0;
 long lastReadingTime = 0;
 
-//Send a write command to SCP1000
-void writeRegister(byte registerName, byte registerValue) {
-  // SCP1000 expects the register name in the upper 6 bits
-  // of the byte:
-  registerName <<= 2;
-  // command (read or write) goes in the lower two bits:
-  registerName |= 0b00000010; //Write command
-
-  // take the chip select low to select the device:
-  digitalWrite(chipSelectPin, LOW); 
-
-  SPI.transfer(registerName); //Send register location
-  SPI.transfer(registerValue); //Send value to record into register
-
-  // take the chip select high to de-select:
-  digitalWrite(chipSelectPin, HIGH); 
-}
-
-
-//Read register from the SCP1000:
-unsigned int readRegister(byte registerName, int numBytes) {
-  byte inByte = 0;           // incoming from  the SPI read
-  unsigned int result = 0;   // result to return 
-
-  // SCP1000 expects the register name in the upper 6 bits
-  // of the byte:
-  registerName <<=  2;
-  // command (read or write) goes in the lower two bits:
-  registerName &= 0b11111100; //Read command
-
-  // take the chip select low to select the device:
-  digitalWrite(chipSelectPin, LOW); 
-  // send the device the register you want to read:
-  int command = SPI.transfer(registerName); 
-  // send a value of 0 to read the first byte returned:
-  inByte = SPI.transfer(0x00); 
-  
-  result = inByte;
-  // if there's more than one byte returned, 
-  // shift the first byte then get the second byte:
-  if (numBytes > 1){
-    result = inByte << 8;
-    inByte = SPI.transfer(0x00); 
-    result = result |inByte;
-  }
-  // take the chip select high to de-select:
-  digitalWrite(chipSelectPin, HIGH); 
-  // return the result:
-  return(result);
-}
-
 void setup() {
   // start the SPI library:
   SPI.begin();
@@ -219,3 +168,55 @@ void listenForEthernetClients() {
     client.stop();
   }
 } 
+
+
+//Send a write command to SCP1000
+void writeRegister(byte registerName, byte registerValue) {
+  // SCP1000 expects the register name in the upper 6 bits
+  // of the byte:
+  registerName <<= 2;
+  // command (read or write) goes in the lower two bits:
+  registerName |= 0b00000010; //Write command
+
+  // take the chip select low to select the device:
+  digitalWrite(chipSelectPin, LOW);
+
+  SPI.transfer(registerName); //Send register location
+  SPI.transfer(registerValue); //Send value to record into register
+
+  // take the chip select high to de-select:
+  digitalWrite(chipSelectPin, HIGH);
+}
+
+
+//Read register from the SCP1000:
+unsigned int readRegister(byte registerName, int numBytes) {
+  byte inByte = 0;           // incoming from  the SPI read
+  unsigned int result = 0;   // result to return
+
+  // SCP1000 expects the register name in the upper 6 bits
+  // of the byte:
+  registerName <<=  2;
+  // command (read or write) goes in the lower two bits:
+  registerName &= 0b11111100; //Read command
+
+  // take the chip select low to select the device:
+  digitalWrite(chipSelectPin, LOW);
+  // send the device the register you want to read:
+  int command = SPI.transfer(registerName);
+  // send a value of 0 to read the first byte returned:
+  inByte = SPI.transfer(0x00);
+
+  result = inByte;
+  // if there's more than one byte returned,
+  // shift the first byte then get the second byte:
+  if (numBytes > 1){
+    result = inByte << 8;
+    inByte = SPI.transfer(0x00);
+    result = result |inByte;
+  }
+  // take the chip select high to de-select:
+  digitalWrite(chipSelectPin, HIGH);
+  // return the result:
+  return(result);
+}
diff --git a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino 
b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
index c67c3fe..a476aac 100644
--- a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
+++ b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
@@ -45,30 +45,6 @@ byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing pack
 // A UDP instance to let us send and receive packets over UDP
 EthernetUDP Udp;
 
-// send an NTP request to the time server at the given address
-unsigned long sendNTPpacket(IPAddress& address)
-{
-  // set all bytes in the buffer to 0
-  memset(packetBuffer, 0, NTP_PACKET_SIZE);
-  // Initialize values needed to form NTP request
-  // (see URL above for details on the packets)
-  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
-  packetBuffer[1] = 0;     // Stratum, or type of clock
-  packetBuffer[2] = 6;     // Polling Interval
-  packetBuffer[3] = 0xEC;  // Peer Clock Precision
-  // 8 bytes of zero for Root Delay & Root Dispersion
-  packetBuffer[12]  = 49;
-  packetBuffer[13]  = 0x4E;
-  packetBuffer[14]  = 49;
-  packetBuffer[15]  = 52;
-
-  // all NTP fields have been given values, now
-  // you can send a packet requesting a timestamp:
-  Udp.beginPacket(address, 123); //NTP requests are to port 123
-  Udp.write(packetBuffer,NTP_PACKET_SIZE);
-  Udp.endPacket();
-}
-
 void setup() 
 {
  // Open serial communications and wait for port to open:
@@ -139,6 +115,31 @@ void loop()
   delay(10000); 
 }
 
+// send an NTP request to the time server at the given address
+unsigned long sendNTPpacket(IPAddress& address)
+{
+  // set all bytes in the buffer to 0
+  memset(packetBuffer, 0, NTP_PACKET_SIZE);
+  // Initialize values needed to form NTP request
+  // (see URL above for details on the packets)
+  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
+  packetBuffer[1] = 0;     // Stratum, or type of clock
+  packetBuffer[2] = 6;     // Polling Interval
+  packetBuffer[3] = 0xEC;  // Peer Clock Precision
+  // 8 bytes of zero for Root Delay & Root Dispersion
+  packetBuffer[12]  = 49;
+  packetBuffer[13]  = 0x4E;
+  packetBuffer[14]  = 49;
+  packetBuffer[15]  = 52;
+
+  // all NTP fields have been given values, now
+  // you can send a packet requesting a timestamp:
+  Udp.beginPacket(address, 123); //NTP requests are to port 123
+  Udp.write(packetBuffer,NTP_PACKET_SIZE);
+  Udp.endPacket();
+}
+
+
 
 
 
diff --git a/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino 
b/libraries/Ethernet/examples/XivelyClient/XivelyClient.ino
similarity index 88%
rename from libraries/Ethernet/examples/PachubeClient/PachubeClient.ino
rename to libraries/Ethernet/examples/XivelyClient/XivelyClient.ino
index dfd2d40..9edbacf 100644
--- a/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino
+++ b/libraries/Ethernet/examples/XivelyClient/XivelyClient.ino
@@ -1,40 +1,40 @@
 /*
-  Pachube sensor client
- 
- This sketch connects an analog sensor to Pachube (http://www.pachube.com)
+  Xively sensor client
+
+ This sketch connects an analog sensor to Xively (http://www.xively.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 Xively.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
  modified 9 Apr 2012
  by Tom Igoe with input from Usman Haque and Joe Saavedra
- 
-http://arduino.cc/en/Tutorial/PachubeClient
+
+http://arduino.cc/en/Tutorial/XivelyClient
  This code is in the public domain.
- 
+
  */
 
 #include <SPI.h>
 #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 xively 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[] = { 
+byte mac[] = {
   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
 
 // fill in an available IP address on your network here,
@@ -45,12 +45,12 @@ 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,122);      // numeric IP for api.xively.com
+//char server[] = "api.xively.com";   // name address for xively 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 Xively.com
 
 void setup() {
  // Open serial communications and wait for port to open:
@@ -70,7 +70,7 @@ void setup() {
 
 void loop() {
   // read the analog sensor:
-  int sensorReading = analogRead(A0);   
+  int sensorReading = analogRead(A0);
 
   // if there's incoming data from the net connection.
   // send it out the serial port.  This is for debugging
@@ -107,8 +107,8 @@ void sendData(int 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.xively.com");
+    client.print("X-XivelyApiKey: ");
     client.println(APIKEY);
     client.print("User-Agent: ");
     client.println(USERAGENT);
@@ -127,8 +127,8 @@ void sendData(int thisData) {
     // 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");
@@ -149,7 +149,7 @@ void sendData(int thisData) {
 int getLength(int someValue) {
   // there's at least one byte:
   int digits = 1;
-  // continually divide the value by ten, 
+  // 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;
@@ -160,4 +160,3 @@ int getLength(int someValue) {
   // return the number of digits:
   return digits;
 }
-
diff --git a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino 
b/libraries/Ethernet/examples/XivelyClientString/XivelyClientString.ino
similarity index 85%
rename from libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino
rename to libraries/Ethernet/examples/XivelyClientString/XivelyClientString.ino
index 26472d1..b0100b7 100644
--- a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino
+++ b/libraries/Ethernet/examples/XivelyClientString/XivelyClientString.ino
@@ -1,45 +1,45 @@
 /*
-  Pachube sensor client with Strings
- 
- This sketch connects an analog sensor to Pachube (http://www.pachube.com)
+  Xively sensor client with Strings
+
+ This sketch connects an analog sensor to Xively (http://www.xively.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 xively.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.  
- 
+ version 0019.
+
  Circuit:
  * Analog sensor attached to analog in 0
  * Ethernet shield attached to pins 10, 11, 12, 13
- 
+
  created 15 March 2010
  modified 9 Apr 2012
  by Tom Igoe with input from Usman Haque and Joe Saavedra
  modified 8 September 2012
  by Scott Fitzgerald
- 
- http://arduino.cc/en/Tutorial/PachubeClientString
+
+ http://arduino.cc/en/Tutorial/XivelyClientString
  This code is in the public domain.
- 
+
  */
 
 #include <SPI.h>
 #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 Xively 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[] = { 
+  byte mac[] = {
   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
 
 // fill in an available IP address on your network here,
@@ -51,12 +51,12 @@ 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.pachube.com
-//char server[] = "api.pachube.com";   // name address for pachube API
+IPAddress server(216,52,233,121);      // numeric IP for api.xively.com
+//char server[] = "api.xively.com";   // name address for xively 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 xively.com
 
 void setup() {
  // Open serial communications and wait for port to open:
@@ -78,14 +78,14 @@ void setup() {
 
 void loop() {
   // read the analog sensor:
-  int sensorReading = analogRead(A0);   
+  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
-  // pachube feed is set up to handle multiple values:
+  // xively feed is set up to handle multiple values:
   int otherSensorReading = analogRead(A1);
   dataString += "\nsensor2,";
   dataString += otherSensorReading;
@@ -107,7 +107,7 @@ void loop() {
   }
 
   // if you're not connected, and ten seconds have passed since
-  // your last connection, then connect again and send data: 
+  // your last connection, then connect again and send data:
   if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
     sendData(dataString);
   }
@@ -125,8 +125,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.xively.com");
+    client.print("X-xivelyApiKey: ");
     client.println(APIKEY);
     client.print("User-Agent: ");
     client.println(USERAGENT);
@@ -140,7 +140,7 @@ void sendData(String thisData) {
 
     // here's the actual content of the PUT request:
     client.println(thisData);
-  } 
+  }
   else {
     // if you couldn't make a connection:
     Serial.println("connection failed");
@@ -151,4 +151,3 @@ void sendData(String thisData) {
   // note the time that the connection was made or attempted:
   lastConnectionTime = millis();
 }
-
diff --git a/libraries/Firmata/examples/I2CFirmata/I2CFirmata.ino 
b/libraries/Firmata/examples/I2CFirmata/I2CFirmata.ino
index 7ed7b63..1da8963 100644
--- a/libraries/Firmata/examples/I2CFirmata/I2CFirmata.ino
+++ b/libraries/Firmata/examples/I2CFirmata/I2CFirmata.ino
@@ -55,22 +55,6 @@ byte i2cRxData[32];
 boolean readingContinuously = false;
 byte queryIndex = 0;
 
-/* reference: BlinkM_funcs.h by Tod E. Kurt, ThingM, http://thingm.com/ */
-// Enables Pins A2 and A3 to be used as GND and Power
-// so that I2C devices can be plugged directly
-// into Arduino header (pins A2 - A5)
-static void enablePowerPins(byte pwrpin, byte gndpin)
-{
-  if(powerPinsEnabled == 0) {
-    DDRC |= _BV(pwrpin) | _BV(gndpin);
-    PORTC &=~ _BV(gndpin);
-    PORTC |=  _BV(pwrpin);
-    powerPinsEnabled = 1;
-    Firmata.sendString("Power pins enabled");
-    delay(100);
-  }
-}
-
 void readAndReportData(byte address, int theRegister, byte numBytes)
 {
   if (theRegister != REGISTER_NOT_SPECIFIED) {
@@ -196,6 +180,22 @@ void systemResetCallback()
   queryIndex = 0;
 }
 
+/* reference: BlinkM_funcs.h by Tod E. Kurt, ThingM, http://thingm.com/ */
+// Enables Pins A2 and A3 to be used as GND and Power
+// so that I2C devices can be plugged directly
+// into Arduino header (pins A2 - A5)
+static void enablePowerPins(byte pwrpin, byte gndpin)
+{
+  if(powerPinsEnabled == 0) {
+    DDRC |= _BV(pwrpin) | _BV(gndpin);
+    PORTC &=~ _BV(gndpin);
+    PORTC |=  _BV(pwrpin);
+    powerPinsEnabled = 1;
+    Firmata.sendString("Power pins enabled");
+    delay(100);
+  }
+}
+
 void setup()
 {
   Firmata.setFirmwareVersion(2, 0);
diff --git a/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino 
b/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino
new file mode 100644
index 0000000..11b7287
--- /dev/null
+++ b/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino
@@ -0,0 +1,140 @@
+/*
+  LiquidCrystal Library - Custom Characters
+
+ Demonstrates how to add custom characters on an LCD  display.
+ The LiquidCrystal library works with all LCD displays that are
+ compatible with the  Hitachi HD44780 driver. There are many of
+ them out there, and you can usually tell them by the 16-pin interface.
+
+ This sketch prints "I <heart> Arduino!" and a little dancing man
+ to the LCD.
+
+  The circuit:
+ * LCD RS pin to digital pin 12
+ * LCD Enable pin to digital pin 11
+ * LCD D4 pin to digital pin 5
+ * LCD D5 pin to digital pin 4
+ * LCD D6 pin to digital pin 3
+ * LCD D7 pin to digital pin 2
+ * LCD R/W pin to ground
+ * 10K potentiometer:
+ * ends to +5V and ground
+ * wiper to LCD VO pin (pin 3)
+ * 10K poterntiometer on pin A0
+
+ created 21 Mar 2011
+ by Tom Igoe
+ modified 11 Nov 2013
+ by Scott Fitzgerald
+
+ Based on Adafruit's example at
+ https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde
+
+ This example code is in the public domain.
+ http://www.arduino.cc/en/Tutorial/LiquidCrystal
+
+ Also useful:
+ http://icontexto.com/charactercreator/
+
+ */
+
+// include the library code:
+#include <LiquidCrystal.h>
+
+// initialize the library with the numbers of the interface pins
+LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
+
+// make some custom characters:
+byte heart[8] = {
+  0b00000,
+  0b01010,
+  0b11111,
+  0b11111,
+  0b11111,
+  0b01110,
+  0b00100,
+  0b00000
+};
+
+byte smiley[8] = {
+  0b00000,
+  0b00000,
+  0b01010,
+  0b00000,
+  0b00000,
+  0b10001,
+  0b01110,
+  0b00000
+};
+
+byte frownie[8] = {
+  0b00000,
+  0b00000,
+  0b01010,
+  0b00000,
+  0b00000,
+  0b00000,
+  0b01110,
+  0b10001
+};
+
+byte armsDown[8] = {
+  0b00100,
+  0b01010,
+  0b00100,
+  0b00100,
+  0b01110,
+  0b10101,
+  0b00100,
+  0b01010
+};
+
+byte armsUp[8] = {
+  0b00100,
+  0b01010,
+  0b00100,
+  0b10101,
+  0b01110,
+  0b00100,
+  0b00100,
+  0b01010
+};
+
+void setup() {
+  // initialize LCD and set up the number of columns and rows:
+  lcd.begin(16, 2);
+
+  // create a new character
+  lcd.createChar(0, heart);
+  // create a new character
+  lcd.createChar(1, smiley);
+  // create a new character
+  lcd.createChar(2, frownie);
+  // create a new character
+  lcd.createChar(3, armsDown);
+  // create a new character
+  lcd.createChar(4, armsUp);
+
+  // Print a message to the lcd.
+  lcd.print("I ");
+  lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
+  lcd.print(" Arduino! ");
+  lcd.write(1);
+
+}
+
+void loop() {
+  // read the potentiometer on A0:
+  int sensorReading = analogRead(A0);
+  // map the result to 200 - 1000:
+  int delayTime = map(sensorReading, 0, 1023, 200, 1000);
+  // set the cursor to the bottom row, 5th position:
+  lcd.setCursor(4, 1);
+  // draw the little man, arms down:
+  lcd.write(3);
+  delay(delayTime);
+  lcd.setCursor(4, 1);
+  // draw him arms up:
+  lcd.write(4);
+  delay(delayTime);
+}
diff --git a/libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino 
b/libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino
index e99957d..eaf0f6f 100644
--- a/libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino
+++ b/libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino
@@ -17,6 +17,8 @@
  * LCD D6 pin to digital pin 3
  * LCD D7 pin to digital pin 2
  * LCD R/W pin to ground
+ * LCD VSS pin to ground
+ * LCD VCC pin to 5V
  * 10K resistor:
  * ends to +5V and ground
  * wiper to LCD VO pin (pin 3)
diff --git a/libraries/SD/examples/listfiles/listfiles.ino b/libraries/SD/examples/listfiles/listfiles.ino
index d403073..aaa9913 100644
--- a/libraries/SD/examples/listfiles/listfiles.ino
+++ b/libraries/SD/examples/listfiles/listfiles.ino
@@ -1,7 +1,9 @@
 /*
-  SD card basic file example
+  Listfiles
  
- This example shows how to create and destroy an SD card file  
+ This example shows how print out the files in a
+ directory on a SD card
+
  The circuit:
  * SD card attached to SPI bus as follows:
  ** MOSI - pin 11
@@ -13,6 +15,8 @@
  by David A. Mellis
  modified 9 Apr 2012
  by Tom Igoe
+ modified 2 Feb 2014
+ by Scott Fitzgerald
  
  This example code is in the public domain.
         
@@ -29,7 +33,6 @@ void setup()
     ; // 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 
@@ -37,7 +40,7 @@ void setup()
   // or the SD library functions will not work. 
   pinMode(10, OUTPUT);
 
-  if (!SD.begin(10)) {
+  if (!SD.begin(4)) {
     Serial.println("initialization failed!");
     return;
   }
@@ -61,7 +64,6 @@ void printDirectory(File dir, int numTabs) {
      File entry =  dir.openNextFile();
      if (! entry) {
        // no more files
-       //Serial.println("**nomorefiles**");
        break;
      }
      for (uint8_t i=0; i<numTabs; i++) {
diff --git a/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino 
b/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino
index 828fbd6..9d77a42 100644
--- a/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino
+++ b/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino
@@ -37,6 +37,53 @@ const byte WRITE = 0b00000010;   // SCP1000's write command
 const int dataReadyPin = 6;
 const int chipSelectPin = 7;
 
+void setup() {
+  Serial.begin(9600);
+
+  // start the SPI library:
+  SPI.begin();
+
+  // initalize the  data ready and chip select pins:
+  pinMode(dataReadyPin, INPUT);
+  pinMode(chipSelectPin, OUTPUT);
+
+  //Configure SCP1000 for low noise configuration:
+  writeRegister(0x02, 0x2D);
+  writeRegister(0x01, 0x03);
+  writeRegister(0x03, 0x02);
+  // give the sensor time to set up:
+  delay(100);
+}
+
+void loop() {
+  //Select High Resolution Mode
+  writeRegister(0x03, 0x0A);
+
+  // don't do anything until the data ready pin is high:
+  if (digitalRead(dataReadyPin) == HIGH) {
+    //Read the temperature data
+    int tempData = readRegister(0x21, 2);
+
+    // convert the temperature to celsius and display it:
+    float realTemp = (float)tempData / 20.0;
+    Serial.print("Temp[C]=");
+    Serial.print(realTemp);
+
+
+    //Read the pressure data highest 3 bits:
+    byte  pressure_data_high = readRegister(0x1F, 1);
+    pressure_data_high &= 0b00000111; //you only needs bits 2 to 0
+
+    //Read the pressure data lower 16 bits:
+    unsigned int pressure_data_low = readRegister(0x20, 2);
+    //combine the two parts into one 19-bit number:
+    long pressure = ((pressure_data_high << 16) | pressure_data_low)/4;
+
+    // display the temperature:
+    Serial.println("\tPressure [Pa]=" + String(pressure));
+  }
+}
+
 //Read from or write to register from the SCP1000:
 unsigned int readRegister(byte thisRegister, int bytesToRead ) {
   byte inByte = 0;           // incoming byte from the SPI
@@ -75,6 +122,7 @@ unsigned int readRegister(byte thisRegister, int bytesToRead ) {
 
 
 //Sends a write command to SCP1000
+
 void writeRegister(byte thisRegister, byte thisValue) {
 
   // SCP1000 expects the register address in the upper 6 bits
@@ -93,49 +141,3 @@ void writeRegister(byte thisRegister, byte thisValue) {
   digitalWrite(chipSelectPin, HIGH);
 }
 
-void setup() {
-  Serial.begin(9600);
-
-  // start the SPI library:
-  SPI.begin();
-
-  // initalize the  data ready and chip select pins:
-  pinMode(dataReadyPin, INPUT);
-  pinMode(chipSelectPin, OUTPUT);
-
-  //Configure SCP1000 for low noise configuration:
-  writeRegister(0x02, 0x2D);
-  writeRegister(0x01, 0x03);
-  writeRegister(0x03, 0x02);
-  // give the sensor time to set up:
-  delay(100);
-}
-
-void loop() {
-  //Select High Resolution Mode
-  writeRegister(0x03, 0x0A);
-
-  // don't do anything until the data ready pin is high:
-  if (digitalRead(dataReadyPin) == HIGH) {
-    //Read the temperature data
-    int tempData = readRegister(0x21, 2);
-
-    // convert the temperature to celsius and display it:
-    float realTemp = (float)tempData / 20.0;
-    Serial.print("Temp[C]=");
-    Serial.print(realTemp);
-
-
-    //Read the pressure data highest 3 bits:
-    byte  pressure_data_high = readRegister(0x1F, 1);
-    pressure_data_high &= 0b00000111; //you only needs bits 2 to 0
-
-    //Read the pressure data lower 16 bits:
-    unsigned int pressure_data_low = readRegister(0x20, 2);
-    //combine the two parts into one 19-bit number:
-    long pressure = ((pressure_data_high << 16) | pressure_data_low)/4;
-
-    // display the temperature:
-    Serial.println("\tPressure [Pa]=" + String(pressure));
-  }
-}
diff --git 
a/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor/BarometricPressureSensor.ino 
b/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor/BarometricPressureSensor.ino
new file mode 100644
index 0000000..9f99a2d
--- /dev/null
+++ b/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor/BarometricPressureSensor.ino
@@ -0,0 +1,140 @@
+/*
+  SCP1000 Barometric Pressure Sensor Display
+
+ Shows the output of a Barometric Pressure Sensor on a
+ Uses the SPI library. For details on the sensor, see:
+ http://www.sparkfun.com/commerce/product_info.php?products_id=8161
+ http://www.vti.fi/en/support/obsolete_products/pressure_sensors/
+
+ This sketch adapted from Nathan Seidle's SCP1000 example for PIC:
+ http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip
+
+ Circuit:
+ SCP1000 sensor attached to pins 6, 7, 10 - 13:
+ DRDY: pin 6
+ CSB: pin 7
+ MOSI: pin 11
+ MISO: pin 12
+ SCK: pin 13
+
+ created 31 July 2010
+ modified 14 August 2010
+ by Tom Igoe
+ */
+
+// the sensor communicates using SPI, so include the library:
+#include <SPI.h>
+
+//Sensor's memory register addresses:
+const int PRESSURE = 0x1F;      //3 most significant bits of pressure
+const int PRESSURE_LSB = 0x20;  //16 least significant bits of pressure
+const int TEMPERATURE = 0x21;   //16 bit temperature reading
+cont byte READ = 0b00000000;     // SCP1000's read command
+const byte WRITE = 0b00000010;   // SCP1000's write command
+// pins used for the connection with the sensor
+// the other you need are controlled by the SPI library):
+const int dataReadyPin = 6;
+const int chipSelectPin = 7;
+
+void setup() {
+  Serial.begin(9600);
+
+  // start the SPI library:
+  SPI.begin();
+
+  // initalize the  data ready and chip select pins:
+  pinMode(dataReadyPin, INPUT);
+  pinMode(chipSelectPin, OUTPUT);
+
+  //Configure SCP1000 for low noise configuration:
+  writeRegister(0x02, 0x2D);
+  writeRegister(0x01, 0x03);
+  writeRegister(0x03, 0x02);
+  // give the sensor time to set up:
+  delay(100);
+}
+
+void loop() {
+  //Select High Resolution Mode
+  writeRegister(0x03, 0x0A);
+
+  // don't do anything until the data ready pin is high:
+  if (digitalRead(dataReadyPin) == HIGH) {
+    //Read the temperature data
+    int tempData = readRegister(0x21, 2);
+
+    // convert the temperature to celsius and display it:
+    float realTemp = (float)tempData / 20.0;
+    Serial.print("Temp[C]=");
+    Serial.print(realTemp);
+
+
+    //Read the pressure data highest 3 bits:
+    byte  pressure_data_high = readRegister(0x1F, 1);
+    pressure_data_high &= 0b00000111; //you only needs bits 2 to 0
+
+    //Read the pressure data lower 16 bits:
+    unsigned int pressure_data_low = readRegister(0x20, 2);
+    //combine the two parts into one 19-bit number:
+    long pressure = ((pressure_data_high << 16) | pressure_data_low)/4;
+
+    // display the temperature:
+    Serial.println("\tPressure [Pa]=" + String(pressure));
+  }
+}
+
+//Read from or write to register from the SCP1000:
+unsigned int readRegister(byte thisRegister, int bytesToRead ) {
+  byte inByte = 0;           // incoming byte from the SPI
+  unsigned int result = 0;   // result to return
+
+  // SCP1000 expects the register name in the upper 6 bits
+  // of the byte. So shift the bits left by two bits:
+  thisRegister = thisRegister << 2;
+  // now combine the address and the command into one byte
+  dataToSend = thisRegister & READ;
+
+  // take the chip select low to select the device:
+  digitalWrite(chipSelectPin, LOW);
+  // send the device the register you want to read:
+  SPI.transfer(dataToSend);
+  // send a value of 0 to read the first byte returned:
+  result = SPI.transfer(0x00);
+  // decrement the number of bytes left to read:
+  bytesToRead--;
+  // if you still have another byte to read:
+  if (bytesToRead > 0) {
+    // shift the first byte left, then get the second byte:
+    result = result << 8;
+    inByte = SPI.transfer(0x00);
+    // combine the byte you just got with the previous one:
+    result = result | inByte;
+    // decrement the number of bytes left to read:
+    bytesToRead--;
+  }
+  // take the chip select high to de-select:
+  digitalWrite(chipSelectPin, HIGH);
+  // return the result:
+  return(result);
+}
+
+
+//Sends a write command to SCP1000
+
+void writeRegister(byte thisRegister, byte thisValue) {
+
+  // SCP1000 expects the register address in the upper 6 bits
+  // of the byte. So shift the bits left by two bits:
+  thisRegister = thisRegister << 2;
+  // now combine the register address and the command into one byte:
+  dataToSend = thisRegister | WRITE;
+
+  // take the chip select low to select the device:
+  digitalWrite(chipSelectPin, LOW);
+
+  SPI.transfer(dataToSend); //Send register location
+  SPI.transfer(thisValue);  //Send value to record into register
+
+  // take the chip select high to de-select:
+  digitalWrite(chipSelectPin, HIGH);
+}
diff --git a/libraries/Servo/examples/Knob/Knob.ino b/libraries/Servo/examples/Knob/Knob.ino
index 886e107..8ddd5b4 100644
--- a/libraries/Servo/examples/Knob/Knob.ino
+++ b/libraries/Servo/examples/Knob/Knob.ino
@@ -1,5 +1,11 @@
-// Controlling a servo position using a potentiometer (variable resistor) 
-// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> 
+/*
+ Controlling a servo position using a potentiometer (variable resistor)
+ by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
+
+ modified on 8 Nov 2013
+ by Scott Fitzgerald
+ http://arduino.cc/en/Tutorial/Knob
+*/
 
 #include <Servo.h> 
  
@@ -16,7 +22,7 @@ void setup()
 void loop() 
 { 
   val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
-  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
+  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
   myservo.write(val);                  // sets the servo position according to the scaled value 
   delay(15);                           // waits for the servo to get there 
 } 
diff --git a/libraries/Servo/examples/Sweep/Sweep.ino b/libraries/Servo/examples/Sweep/Sweep.ino
index fb326e7..c5cdc01 100644
--- a/libraries/Servo/examples/Sweep/Sweep.ino
+++ b/libraries/Servo/examples/Sweep/Sweep.ino
@@ -1,12 +1,16 @@
-// Sweep
-// by BARRAGAN <http://barraganstudio.com> 
-// This example code is in the public domain.
+/* Sweep
+ by BARRAGAN <http://barraganstudio.com>
+ This example code is in the public domain.
 
+ modified 8 Nov 2013
+ by Scott Fitzgerald
+ http://arduino.cc/en/Tutorial/Sweep
+*/
 
 #include <Servo.h> 
  
 Servo myservo;  // create servo object to control a servo 
-                // a maximum of eight servo objects can be created 
+                // twelve servo objects can be created on most boards
  
 int pos = 0;    // variable to store the servo position 
  
@@ -15,15 +19,14 @@ void setup()
   myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
 } 
  
- 
 void loop() 
 { 
-  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
+  for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
   {                                  // in steps of 1 degree 
     myservo.write(pos);              // tell servo to go to position in variable 'pos' 
     delay(15);                       // waits 15ms for the servo to reach the position 
   } 
-  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
+  for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees
   {                                
     myservo.write(pos);              // tell servo to go to position in variable 'pos' 
     delay(15);                       // waits 15ms for the servo to reach the position 
diff --git a/libraries/SoftwareSerial/SoftwareSerial.cpp b/libraries/SoftwareSerial/SoftwareSerial.cpp
index 64496fe..3360734 100644
--- a/libraries/SoftwareSerial/SoftwareSerial.cpp
+++ b/libraries/SoftwareSerial/SoftwareSerial.cpp
@@ -352,13 +352,13 @@ SoftwareSerial::~SoftwareSerial()
   end();
 }
 
-void SoftwareSerial::setTX(uint8_t tx)
-{
-  pinMode(tx, OUTPUT);
-  digitalWrite(tx, HIGH);
-  _transmitBitMask = digitalPinToBitMask(tx);
-  uint8_t port = digitalPinToPort(tx);
-  _transmitPortRegister = portOutputRegister(port);
+void SoftwareSerial::setTX(uint8_t tx)
+{
+  pinMode(tx, OUTPUT);
+  digitalWrite(tx, _inverse_logic ? LOW : HIGH);
+  _transmitBitMask = digitalPinToBitMask(tx);
+  uint8_t port = digitalPinToPort(tx);
+  _transmitPortRegister = portOutputRegister(port);
 }
 
 void SoftwareSerial::setRX(uint8_t rx)
diff --git a/libraries/SoftwareSerial/keywords.txt b/libraries/SoftwareSerial/keywords.txt
index 90d4c15..aaea17c 100644
--- a/libraries/SoftwareSerial/keywords.txt
+++ b/libraries/SoftwareSerial/keywords.txt
@@ -1,12 +1,13 @@
 #######################################
-# Syntax Coloring Map for NewSoftSerial
+# Syntax Coloring Map for SoftwareSerial
+# (formerly NewSoftSerial)
 #######################################
 
 #######################################
 # Datatypes (KEYWORD1)
 #######################################
 
-NewSoftSerial  KEYWORD1
+SoftwareSerial KEYWORD1
 
 #######################################
 # Methods and Functions (KEYWORD2)
@@ -15,11 +16,13 @@ NewSoftSerial       KEYWORD1
 begin  KEYWORD2
 end    KEYWORD2
 read   KEYWORD2
+write  KEYWORD2
 available      KEYWORD2
 isListening    KEYWORD2
 overflow       KEYWORD2
 flush  KEYWORD2
 listen KEYWORD2
+peek   KEYWORD2
 
 #######################################
 # Constants (LITERAL1)



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