コード例 #1
0
ファイル: main.cpp プロジェクト: coreymason/smart-greenhouse
void loop() {
  unsigned long currentTime = Time.now();
  //TODO: if targets -1, don't do any control

  //Request time synchronization from the Particle Cloud every 24 hours
  if (millis() - lastTimeSync > ONE_DAY_MILLIS) {
    Particle.syncTime();
    lastTimeSync = millis();
  }

  //Update time zone at DSTJumpHour incase DST is now in effect
  if(Time.hour(currentTime) == DSTJumpHour && Time.minute(currentTime) == 0) {
    Time.zone(isDST(Time.day(currentTime), Time.month(currentTime), Time.weekday(currentTime), preferences.DSTRule) ? preferences.timeZone + 1 : preferences.timeZone);
  }

  //Record data from sensors every minute
  if(millis() - lastDataSync > dataSyncFrequency) {
    temperature = tempHumidSensor.readTemperature();
    humidity = tempHumidSensor.readHumidity();
    light = lightSensor.getFullLuminosity();
    fullLight = light & 0xFFFF;
    irLight = light >> 16;
    visibleLight = fullLight - irLight;
    lux = lightSensor.calculateLux(fullLight, irLight);
    //TODO: soil moisture sensor
    if(postToPhant() == 0) {
      //Success
    } else {
      //failed
      //TODO: Handle failure
    }
  }
コード例 #2
0
ファイル: sensors.cpp プロジェクト: rustychris/weatherpi
void tsl2591_loop(void)
{
  // More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum
  // That way you can do whatever math and comparisons you want!
  float lux;
  uint32_t lum = tsl.getFullLuminosity();
  uint16_t ir, full;
  ir = lum >> 16;
  full = lum & 0xFFFF;
  // the second argument should be IR, but there are some weird faults
  // and that results in negative values often.  So cheat and just provide
  // a 0 there.
  lux=tsl.calculateLux(full, 0);

  if(false) {
    Serial.print(F("[ ")); Serial.print(millis()); Serial.print(F(" ms ] "));
    Serial.print(F("IR: ")); Serial.print(ir);  Serial.print(F("  "));
    Serial.print(F("Full: ")); Serial.print(full); Serial.print(F("  "));
    Serial.print(F("Visible: ")); Serial.print(full - ir); Serial.print(F("  "));
    Serial.print(F("Lux: ")); Serial.println(lux,6);
  }

  publish_value("lux",lux,2);
}