test everything
This commit is contained in:
parent
cd756e5994
commit
94020b57d2
1 changed files with 27 additions and 56 deletions
83
src/main.cpp
83
src/main.cpp
|
@ -13,12 +13,8 @@
|
||||||
|
|
||||||
void printValues();
|
void printValues();
|
||||||
|
|
||||||
const int maxCount = 10;
|
|
||||||
int count = 0;
|
|
||||||
bool noise = false;
|
|
||||||
bool noiseActive = false;
|
|
||||||
|
|
||||||
float ppm;
|
float ppm;
|
||||||
|
bool noiseActive;
|
||||||
|
|
||||||
MQ135 co2_sensor(PIN_MQ135);
|
MQ135 co2_sensor(PIN_MQ135);
|
||||||
Adafruit_BME280 bme;
|
Adafruit_BME280 bme;
|
||||||
|
@ -34,72 +30,47 @@ void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
co2_sensor.setR0(300);
|
co2_sensor.setR0(300);
|
||||||
|
|
||||||
if (!bme.begin(0x76)) {
|
// if (!bme.begin(0x76)) {
|
||||||
Serial.println(F("Could not find a valid BME280 sensor, check wiring!"));
|
// Serial.println(F("Could not find a valid BME280 sensor, check wiring!"));
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (count >= maxCount || count < 0) {
|
// float temp = bme.readTemperature();
|
||||||
float temp = bme.readTemperature();
|
// float humidity = bme.readHumidity();
|
||||||
float humidity = bme.readHumidity();
|
ppm = co2_sensor.getCO2();
|
||||||
ppm = co2_sensor.getCorrectedCO2(temp, humidity);
|
|
||||||
|
digitalWrite(PIN_LED_GREEN, 1);
|
||||||
count = 0;
|
digitalWrite(PIN_LED_GREEN2, 1);
|
||||||
noiseActive = false;
|
digitalWrite(PIN_LED_YELLOW, 1);
|
||||||
digitalWrite(PIN_LED_GREEN, 0);
|
digitalWrite(PIN_LED_YELLOW2, 1);
|
||||||
digitalWrite(PIN_LED_GREEN2, 0);
|
digitalWrite(PIN_LED_RED, 1);
|
||||||
digitalWrite(PIN_LED_YELLOW, 0);
|
digitalWrite(PIN_LED_RED2, 1);
|
||||||
digitalWrite(PIN_LED_YELLOW2, 0);
|
|
||||||
digitalWrite(PIN_LED_RED, 0);
|
|
||||||
digitalWrite(PIN_LED_RED2, 0);
|
|
||||||
|
|
||||||
if (ppm < 1000) {
|
printValues();
|
||||||
digitalWrite(PIN_LED_GREEN, 1);
|
|
||||||
if (ppm > 750) {
|
|
||||||
digitalWrite(PIN_LED_GREEN2, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ppm > 1000 && ppm <= 2000) {
|
|
||||||
digitalWrite(PIN_LED_YELLOW, 1);
|
|
||||||
if (ppm > 1500) {
|
|
||||||
digitalWrite(PIN_LED_YELLOW2, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ppm > 2000) {
|
|
||||||
digitalWrite(PIN_LED_RED, 1);
|
|
||||||
if (ppm > 2500) {
|
|
||||||
noiseActive = true;
|
|
||||||
digitalWrite(PIN_LED_RED2, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (noiseActive) {
|
if (noiseActive) {
|
||||||
noise = !noise;
|
digitalWrite(PIN_NOISE, 1);
|
||||||
// digitalWrite(PIN_NOISE, noise);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// digitalWrite(PIN_NOISE, 0);
|
digitalWrite(PIN_NOISE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
count++;
|
// noiseActive = !noiseActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printValues() {
|
void printValues() {
|
||||||
float temp = bme.readTemperature();
|
// float temp = bme.readTemperature();
|
||||||
float humidity = bme.readHumidity();
|
// float humidity = bme.readHumidity();
|
||||||
float ppm = co2_sensor.getCO2();
|
float ppm = co2_sensor.getCO2();
|
||||||
float cppm = co2_sensor.getCorrectedCO2(temp, humidity);
|
// float cppm = co2_sensor.getCorrectedCO2(temp, humidity);
|
||||||
Serial.print("ppm: ");
|
Serial.print("ppm: ");
|
||||||
Serial.println(ppm);
|
Serial.println(ppm);
|
||||||
Serial.print("Temperature: ");
|
// Serial.print("Temperature: ");
|
||||||
Serial.println(temp);
|
// Serial.println(temp);
|
||||||
Serial.print("Humidity: ");
|
// Serial.print("Humidity: ");
|
||||||
Serial.println(humidity);
|
// Serial.println(humidity);
|
||||||
Serial.print("corrected ppm: ");
|
// Serial.print("corrected ppm: ");
|
||||||
Serial.println(cppm);
|
// Serial.println(cppm);
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue