simulate parallelism
This commit is contained in:
86
aqi.ino
86
aqi.ino
@@ -8,6 +8,26 @@ SensirionI2CSen44 sen44;
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
const int buttonPin = 6;
|
||||
|
||||
// to simulate "parallelism"
|
||||
unsigned long currentTime;
|
||||
unsigned long sen44Time = 0;
|
||||
unsigned long lcdTime = 0;
|
||||
unsigned long buttonTime = 0;
|
||||
|
||||
// display standard values by default
|
||||
bool isStandardValues = true;
|
||||
|
||||
// sen44 values
|
||||
uint16_t massConcentrationPm1p0 = 0;
|
||||
uint16_t massConcentrationPm2p5 = 0;
|
||||
uint16_t massConcentrationPm4p0 = 0;
|
||||
uint16_t massConcentrationPm10p0 = 0;
|
||||
float vocIndex = 0;
|
||||
float ambientHumidity = 0;
|
||||
float ambientTemperature = 0;
|
||||
float feelsLikeTemperature = 0;
|
||||
|
||||
// calculate heat index
|
||||
float heatIndex(float t, float rh) {
|
||||
float hi = 0.0;
|
||||
if (t <= 40.0)
|
||||
@@ -32,6 +52,7 @@ float heatIndex(float t, float rh) {
|
||||
return hi;
|
||||
}
|
||||
|
||||
// convert celcius to fahrenheit
|
||||
float celsiusToFahrenheit(float degrees) {
|
||||
return degrees * 1.8 + 32;
|
||||
}
|
||||
@@ -75,21 +96,25 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
currentTime = millis();
|
||||
|
||||
delay(20);
|
||||
|
||||
if (currentTime - buttonTime >= 100) {
|
||||
buttonTime = currentTime;
|
||||
|
||||
if (digitalRead(buttonPin) == LOW) {
|
||||
isStandardValues = !isStandardValues;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentTime - sen44Time >= 1000) {
|
||||
sen44Time = currentTime;
|
||||
|
||||
uint16_t error;
|
||||
char errorMessage[256];
|
||||
|
||||
delay(1000);
|
||||
|
||||
// Read Measurement
|
||||
uint16_t massConcentrationPm1p0;
|
||||
uint16_t massConcentrationPm2p5;
|
||||
uint16_t massConcentrationPm4p0;
|
||||
uint16_t massConcentrationPm10p0;
|
||||
float vocIndex;
|
||||
float ambientHumidity;
|
||||
float ambientTemperature;
|
||||
float feelsLikeTemperature;
|
||||
|
||||
error = sen44.readMeasuredMassConcentrationAndAmbientValues(
|
||||
massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
|
||||
massConcentrationPm10p0, vocIndex, ambientHumidity, ambientTemperature);
|
||||
@@ -104,26 +129,14 @@ void loop() {
|
||||
|
||||
ambientTemperature = celsiusToFahrenheit(ambientTemperature);
|
||||
feelsLikeTemperature = heatIndex(ambientTemperature, ambientHumidity);
|
||||
}
|
||||
|
||||
if (currentTime - lcdTime >= 500) {
|
||||
lcdTime = currentTime;
|
||||
|
||||
lcd.clear();
|
||||
|
||||
if (digitalRead(buttonPin) == LOW) {
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(" 1:");
|
||||
lcd.print(massConcentrationPm1p0);
|
||||
|
||||
lcd.setCursor(8, 0);
|
||||
lcd.print(" 2:");
|
||||
lcd.print(massConcentrationPm2p5);
|
||||
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(" 4:");
|
||||
lcd.print(massConcentrationPm4p0);
|
||||
|
||||
lcd.setCursor(8, 1);
|
||||
lcd.print("10:");
|
||||
lcd.print(massConcentrationPm10p0);
|
||||
} else {
|
||||
if (isStandardValues) {
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("t:");
|
||||
lcd.print(round(ambientTemperature));
|
||||
@@ -139,5 +152,22 @@ void loop() {
|
||||
lcd.setCursor(8, 1);
|
||||
lcd.print("v:");
|
||||
lcd.print(vocIndex, 0);
|
||||
} else {
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(" 1:");
|
||||
lcd.print(massConcentrationPm1p0);
|
||||
|
||||
lcd.setCursor(8, 0);
|
||||
lcd.print(" 2:");
|
||||
lcd.print(massConcentrationPm2p5);
|
||||
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(" 4:");
|
||||
lcd.print(massConcentrationPm4p0);
|
||||
|
||||
lcd.setCursor(8, 1);
|
||||
lcd.print("10:");
|
||||
lcd.print(massConcentrationPm10p0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user