Una cosa del genere:
#include <SHT1x.h>
#define dataPin 22 // DATA
#define clockPin 24 // SCK
SHT1x sht1x(dataPin, clockPin); // temp and humidity sensor
const int ledPin = 2; // the number of the LED pin
int ledState = LOW; // ledState used to set the LED
unsigned long previousMillis = 0; // will store last time LED was updated
unsigned long interval = 1000; // interval at which to blink (milliseconds)
unsigned long previousMillis2 = 0;
unsigned long interval2 = 5000;
unsigned long currentMillis;
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("Starting up");
Serial.print("Temperature: ");
Serial.println("F. Humidity: ");
}
void loop()
{
currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
// save the last time you blinked the LED
previousMillis = currentMillis;
}
if(currentMillis - previousMillis2 > interval2) {
float temp_c;
float humidity;
temp_c = sht1x.readTemperatureC();
humidity = sht1x.readHumidity();
Serial.print(temp_c);
Serial.print(" ");
Serial.print(",");
Serial.print(humidity);
Serial.print(" ");
Serial.println(",");
previousMillis2 = currentMillis;
}
}
Compila, ma non l'ho verificato sull'Arduino non avendo il sensore.