<commit_before>/* Shofanduino 2 DHT11, a shower fan arduino project with a digital humidity sensor
 *
 * Copyright (c) 2013, <NAME>, see attached LICENSE file for licensing.
 *
 * I used a library from http://playground.arduino.cc/main/DHT11Lib
 *
 * For more information, see README
 */

#include <dht11.h> // see above for URLs
#include <runningmedian.h>

#define DHT11_PIN 23

// consts for controlling relays
const int K1 = 5;
const int K2 = 6;
const int milliseconds_switch_delay = 100;
const int NormallyConnected = HIGH;
const int NormallyOpen = LOW;
typedef enum {FAN_OFF, FAN_NOCHANGE, FAN_ON};

// DHT consts/variables
dht11 DHT11;

// consts/variables for humidity sensor and averages etc.
const int sensorPin = A0;    // select the input pin for the potentiometer
const int milliseconds_sleep = 5000;
const float min_humidity_diff= 10.0; // RH %
const float max_humidity = 100.0; // needed because we add min_humidity_diff

RunningMedian samples = RunningMedian(3);

const float thresholdHighRatio = 6.0f;
const float thresholdLowRatio = 16.0f;
float thresholdLow = 0.0;
float thresholdHigh = 0.0;
float env_min = 0.0;
float env_max = 0.0;
float humidity = 0.0;
float temperature = 0.0;
float on_off = 0;

// variables for decay
 // number of seconds after which the difference between the humidity and the max envelope should have been halved.
const float p_halflife_max = 604800.0;
//const float p_halflife_min = 86400.0; // same for the min envelope. This is shorter because it needs to change faster.
const float p_halflife_min = 43200.0; // same for the min envelope. This is shorter because it needs to change faster.
float env_max_decay = 0.0;
float env_min_decay = 0.0;

// variables to decide the state of the fan
int state = FAN_OFF; // action to take, based on sensor reading

void getValues() {
  // The sensor can only be read from every 1-2s, and requires a minimum
  // 2s warm-up after power-on.
  delay(milliseconds_sleep);

#ifdef USE_DHT22
  DHT22_ERROR_t errorCode = myDHT22.readData();
  humidity = myDHT22.getHumidity();
  temperature = myDHT22.getTemperatureC();<commit_msg>Tweak variables to improve robustness and response time<commit_after>/* Shofanduino 2 DHT11, a shower fan arduino project with a digital humidity sensor
 *
 * Copyright (c) 2013, <NAME>, see attached LICENSE file for licensing.
 *
 * I used a library from http://playground.arduino.cc/main/DHT11Lib
 *
 * For more information, see README
 */

#include <dht11.h> // see above for URLs
#include <runningmedian.h>

#define DHT11_PIN 23

// consts for controlling relays
const int K1 = 5;
const int K2 = 6;
const int milliseconds_switch_delay = 100;
const int NormallyConnected = HIGH;
const int NormallyOpen = LOW;
typedef enum {FAN_OFF, FAN_NOCHANGE, FAN_ON};

// DHT consts/variables
dht11 DHT11;

// consts/variables for humidity sensor and averages etc.
const int sensorPin = A0;    // select the input pin for the potentiometer
const int milliseconds_sleep = 5000;
const float min_humidity_diff= 10.0; // RH %
const float max_humidity = 100.0; // needed because we add min_humidity_diff

RunningMedian samples = RunningMedian(5);

const float thresholdHighRatio = 8.0f;
const float thresholdLowRatio = 16.0f;
float thresholdLow = 0.0;
float thresholdHigh = 0.0;
float env_min = 0.0;
float env_max = 0.0;
float humidity = 0.0;
float temperature = 0.0;
float on_off = 0;

// variables for decay
 // number of seconds after which the difference between the humidity and the max envelope should have been halved.
const float p_halflife_max = 604800.0;
//const float p_halflife_min = 86400.0; // same for the min envelope. This is shorter because it needs to change faster.
const float p_halflife_min = 43200.0; // same for the min envelope. This is shorter because it needs to change faster.
float env_max_decay = 0.0;
float env_min_decay = 0.0;

// variables to decide the state of the fan
int state = FAN_OFF; // action to take, based on sensor reading

void getValues() {
  // The sensor can only be read from every 1-2s, and requires a minimum
  // 2s warm-up after power-on.
  delay(milliseconds_sleep);

#ifdef USE_DHT22
  DHT22_ERROR_t errorCode = myDHT22.readData();
  humidity = myDHT22.getHumidity();
  temperature = myDHT22.getTemperatureC();
{'fraction_non_alphanumeric': 0.08450704225352113, 'fraction_numerical': 0.04366197183098591, 'mean_word_length': 4.048578199052133, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1202366', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1354, 'n_words': 528}