+/**
+ * ReadSHT1xValues
+ *
+ * Read temperature and humidity values from an SHT1x-series (SHT10,
+ * SHT11, SHT15) sensor.
+ *
+ * Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
+ * www.practicalarduino.com
+ */
 // ROS Setup Stuff
 #include <ros.h>
 #include <std_msgs/String.h>
 #include <std_msgs/Float32.h>
 
 #include <SHT1x.h>
-#define dataPin 10
+
+// Specify data and clock connections and instantiate SHT1x object
+#define dataPin  10
 #define clockPin 11
-
-// Serial Communication Variables
-bool msgReceived = false;   // Flag to indicate receipt of message
-String inString;            // Store user input as string
-char inChar;
-
-// Sensor variables
-float tempC = 0;    // Temperature in Celsius (-40 - 123.8, -40 on error)
-float tempF = 0;    // Temperature in Fahrenheit (-40 - 254.9, -40 on error)
-float humidity = 0; // Humidity (0-100%, negative on error)
-
-// Initialize sensor object
-SHT1x mySensor(dataPin, clockPin);
-
+SHT1x sht1x(dataPin, clockPin);
 
 ros::NodeHandle nh;
 

  //myservo.write(179);   
  // put your main code here, to run repeatedly:

  nh.spinOnce(); // Place this at the end
}

/*
  SerialEvent occurs whenever new data comes in the
  hardware serial RX.  This routine is run between each
  time loop() runs, so using delay inside loop can delay
  response.  Multiple bytes of data may be available.
 */
void serialEvent() 
{
  // Read from Rx until end of data stream, or until '\n' is encountered
  while (Serial.available() && !msgReceived) 
  {
    inChar = (char)Serial.read();          // Get the next byte
    
    // Check for a newline, indicating the end of the message
    if(inChar == '\n') 
    {
      msgReceived = true;    // Set flag to break out of loop and handle message
    } 
    else 
    {
      inString += inChar;    // Append current character to the input string
    }
  }
}

// For linear actuator
int incomingByte = 0;   // for incoming serial data

void setup()
{
   Serial.begin(57600); // Open serial connection to report values to host
   Serial.println("Starting up");

   // Initialize ROS node
   nh.initNode();
   nh.advertise(pub_temp);
   nh.advertise(pub_humid);

   // Setup code for linear actuator
   // put your setup code here, to run once:
   #define AIN1 4
   //#define BIN1 7 
   #define AIN2 5
   //#define BIN2 8
   #define PWMA 6
   //myservo.attach(6);  // attaches the servo on pin 9 to the servo object
   //#define PWMB 9 
   #define STBY 9
   pinMode(AIN1, OUTPUT);
   pinMode(AIN2, OUTPUT);
   
}

void loop()
{
  float temp_c;
  float temp_f;
  float humidity;

  // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  //temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();

  // Print the values to the serial port
  Serial.print("Temperature: ");
  Serial.print(temp_c, DEC);
  Serial.print("C / ");
  //Serial.print(temp_f, DEC);
  //Serial.print("F. Humidity: ");
  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.println("%");

  // ROS stuff
  temp_msg.data = temp_c;
  humid_msg.data = humidity;
  pub_temp.publish(&temp_msg);
  pub_humid.publish(&humid_msg);

  //nh.spinOnce(); Placing this line here prevents it from working

  //delay(2000);

  // send data only when you receive data:
  if (Serial.available() > 0) 
