[gnoduino] examples: recent g++ scope fixes



commit e6ca0fdc812474a2cbf7d4b545f533450454b611
Author: Pascal de Bruijn <pmjdebruijn pcode nl>
Date:   Thu Aug 14 18:40:08 2014 +0200

    examples: recent g++ scope fixes

 .../BarometricPressureWebServer.ino                |  182 +++++++------------
 .../BarometricPressureSensor.ino                   |   95 +++++------
 2 files changed, 113 insertions(+), 164 deletions(-)
---
diff --git a/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino 
b/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino
index 81cc89a..1ee00c3 100644
--- a/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino
+++ b/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino
@@ -56,120 +56,6 @@ float temperature = 0.0;
 long pressure = 0;
 long lastReadingTime = 0;
 
-void setup() {
-  // start the SPI library:
-  SPI.begin();
-
-  // start the Ethernet connection and the server:
-  Ethernet.begin(mac, ip);
-  server.begin();
-
-  // initalize the  data ready and chip select pins:
-  pinMode(dataReadyPin, INPUT);
-  pinMode(chipSelectPin, OUTPUT);
-
-  Serial.begin(9600);
-
-  //Configure SCP1000 for low noise configuration:
-  writeRegister(0x02, 0x2D);
-  writeRegister(0x01, 0x03);
-  writeRegister(0x03, 0x02);
-
-  // give the sensor and Ethernet shield time to set up:
-  delay(1000);
-
-  //Set the sensor to high resolution mode tp start readings:
-  writeRegister(0x03, 0x0A);
-
-}
-
-void loop() { 
-  // check for a reading no more than once a second.
-  if (millis() - lastReadingTime > 1000){
-    // if there's a reading ready, read it:
-    // don't do anything until the data ready pin is high:
-    if (digitalRead(dataReadyPin) == HIGH) {
-      getData();
-      // timestamp the last time you got a reading:
-      lastReadingTime = millis();
-    }
-  }
-
-  // listen for incoming Ethernet connections:
-  listenForEthernetClients();
-}
-
-
-void getData() {
-  Serial.println("Getting reading");
-  //Read the temperature data
-  int tempData = readRegister(0x21, 2);
-
-  // convert the temperature to celsius and display it:
-  temperature = (float)tempData / 20.0;
-
-  //Read the pressure data highest 3 bits:
-  byte  pressureDataHigh = readRegister(0x1F, 1);   
-  pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0
-
-  //Read the pressure data lower 16 bits:
-  unsigned int pressureDataLow = readRegister(0x20, 2);    
-  //combine the two parts into one 19-bit number:
-  pressure = ((pressureDataHigh << 16) | pressureDataLow)/4;
-
-  Serial.print("Temperature: ");
-  Serial.print(temperature);
-  Serial.println(" degrees C");
-  Serial.print("Pressure: " + String(pressure));
-  Serial.println(" Pa");
-}
-
-void listenForEthernetClients() {
-  // listen for incoming clients
-  EthernetClient client = server.available();
-  if (client) {
-    Serial.println("Got a client");
-    // an http request ends with a blank line
-    boolean currentLineIsBlank = true;
-    while (client.connected()) {
-      if (client.available()) {
-        char c = client.read();
-        // if you've gotten to the end of the line (received a newline
-        // character) and the line is blank, the http request has ended,
-        // so you can send a reply
-        if (c == '\n' && currentLineIsBlank) {
-          // send a standard http response header
-          client.println("HTTP/1.1 200 OK");
-          client.println("Content-Type: text/html");
-          client.println();
-          // print the current readings, in HTML format:
-          client.print("Temperature: ");
-          client.print(temperature);
-          client.print(" degrees C");
-          client.println("<br />");
-          client.print("Pressure: " + String(pressure));
-          client.print(" Pa");
-          client.println("<br />");  
-          break;
-        }
-        if (c == '\n') {
-          // you're starting a new line
-          currentLineIsBlank = true;
-        } 
-        else if (c != '\r') {
-          // you've gotten a character on the current line
-          currentLineIsBlank = false;
-        }
-      }
-    }
-    // give the web browser time to receive the data
-    delay(1);
-    // close the connection:
-    client.stop();
-  }
-} 
-
-
 //Send a write command to SCP1000
 void writeRegister(byte registerName, byte registerValue) {
   // SCP1000 expects the register name in the upper 6 bits
@@ -188,7 +74,6 @@ void writeRegister(byte registerName, byte registerValue) {
   digitalWrite(chipSelectPin, HIGH);
 }
 
-
 //Read register from the SCP1000:
 unsigned int readRegister(byte registerName, int numBytes) {
   byte inByte = 0;           // incoming from  the SPI read
@@ -220,3 +105,70 @@ unsigned int readRegister(byte registerName, int numBytes) {
   // return the result:
   return(result);
 }
+
+void getData() {
+  Serial.println("Getting reading");
+  //Read the temperature data
+  int tempData = readRegister(0x21, 2);
+
+  // convert the temperature to celsius and display it:
+  temperature = (float)tempData / 20.0;
+
+  //Read the pressure data highest 3 bits:
+  byte  pressureDataHigh = readRegister(0x1F, 1);
+  pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0
+
+  //Read the pressure data lower 16 bits:
+  unsigned int pressureDataLow = readRegister(0x20, 2);
+  //combine the two parts into one 19-bit number:
+  pressure = ((pressureDataHigh << 16) | pressureDataLow)/4;
+
+  Serial.print("Temperature: ");
+  Serial.print(temperature);
+  Serial.println(" degrees C");
+  Serial.print("Pressure: " + String(pressure));
+  Serial.println(" Pa");
+}
+
+void setup() {
+  // start the SPI library:
+  SPI.begin();
+
+  // start the Ethernet connection and the server:
+  Ethernet.begin(mac, ip);
+  server.begin();
+
+  // initalize the  data ready and chip select pins:
+  pinMode(dataReadyPin, INPUT);
+  pinMode(chipSelectPin, OUTPUT);
+
+  Serial.begin(9600);
+
+  //Configure SCP1000 for low noise configuration:
+  writeRegister(0x02, 0x2D);
+  writeRegister(0x01, 0x03);
+  writeRegister(0x03, 0x02);
+
+  // give the sensor and Ethernet shield time to set up:
+  delay(1000);
+
+  //Set the sensor to high resolution mode tp start readings:
+  writeRegister(0x03, 0x0A);
+
+}
+
+void loop() {
+  // check for a reading no more than once a second.
+  if (millis() - lastReadingTime > 1000){
+    // if there's a reading ready, read it:
+    // don't do anything until the data ready pin is high:
+    if (digitalRead(dataReadyPin) == HIGH) {
+      getData();
+      // timestamp the last time you got a reading:
+      lastReadingTime = millis();
+    }
+  }
+
+  // listen for incoming Ethernet connections:
+  listenForEthernetClients();
+}
diff --git a/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino 
b/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino
index 9d77a42..48c5cca 100644
--- a/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino
+++ b/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino
@@ -37,53 +37,6 @@ 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
@@ -120,9 +73,7 @@ unsigned int readRegister(byte thisRegister, int bytesToRead ) {
   return(result);
 }
 
-
 //Sends a write command to SCP1000
-
 void writeRegister(byte thisRegister, byte thisValue) {
 
   // SCP1000 expects the register address in the upper 6 bits
@@ -141,3 +92,49 @@ 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));
+  }
+}


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