simulate parallelism
This commit is contained in:
132
aqi.ino
132
aqi.ino
@@ -8,6 +8,26 @@ SensirionI2CSen44 sen44;
|
|||||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||||
const int buttonPin = 6;
|
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 heatIndex(float t, float rh) {
|
||||||
float hi = 0.0;
|
float hi = 0.0;
|
||||||
if (t <= 40.0)
|
if (t <= 40.0)
|
||||||
@@ -32,6 +52,7 @@ float heatIndex(float t, float rh) {
|
|||||||
return hi;
|
return hi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert celcius to fahrenheit
|
||||||
float celsiusToFahrenheit(float degrees) {
|
float celsiusToFahrenheit(float degrees) {
|
||||||
return degrees * 1.8 + 32;
|
return degrees * 1.8 + 32;
|
||||||
}
|
}
|
||||||
@@ -75,69 +96,78 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
uint16_t error;
|
currentTime = millis();
|
||||||
char errorMessage[256];
|
|
||||||
|
|
||||||
delay(1000);
|
delay(20);
|
||||||
|
|
||||||
// Read Measurement
|
if (currentTime - buttonTime >= 100) {
|
||||||
uint16_t massConcentrationPm1p0;
|
buttonTime = currentTime;
|
||||||
uint16_t massConcentrationPm2p5;
|
|
||||||
uint16_t massConcentrationPm4p0;
|
|
||||||
uint16_t massConcentrationPm10p0;
|
|
||||||
float vocIndex;
|
|
||||||
float ambientHumidity;
|
|
||||||
float ambientTemperature;
|
|
||||||
float feelsLikeTemperature;
|
|
||||||
|
|
||||||
error = sen44.readMeasuredMassConcentrationAndAmbientValues(
|
if (digitalRead(buttonPin) == LOW) {
|
||||||
massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
|
isStandardValues = !isStandardValues;
|
||||||
massConcentrationPm10p0, vocIndex, ambientHumidity, ambientTemperature);
|
}
|
||||||
|
|
||||||
if (error) {
|
|
||||||
Serial.print("Error trying to execute "
|
|
||||||
"readMeasuredMassConcentrationAndAmbientValues(): ");
|
|
||||||
errorToString(error, errorMessage, 256);
|
|
||||||
Serial.println(errorMessage);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ambientTemperature = celsiusToFahrenheit(ambientTemperature);
|
if (currentTime - sen44Time >= 1000) {
|
||||||
feelsLikeTemperature = heatIndex(ambientTemperature, ambientHumidity);
|
sen44Time = currentTime;
|
||||||
|
|
||||||
lcd.clear();
|
uint16_t error;
|
||||||
|
char errorMessage[256];
|
||||||
|
|
||||||
if (digitalRead(buttonPin) == LOW) {
|
// Read Measurement
|
||||||
lcd.setCursor(0, 0);
|
error = sen44.readMeasuredMassConcentrationAndAmbientValues(
|
||||||
lcd.print(" 1:");
|
massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
|
||||||
lcd.print(massConcentrationPm1p0);
|
massConcentrationPm10p0, vocIndex, ambientHumidity, ambientTemperature);
|
||||||
|
|
||||||
lcd.setCursor(8, 0);
|
if (error) {
|
||||||
lcd.print(" 2:");
|
Serial.print("Error trying to execute "
|
||||||
lcd.print(massConcentrationPm2p5);
|
"readMeasuredMassConcentrationAndAmbientValues(): ");
|
||||||
|
errorToString(error, errorMessage, 256);
|
||||||
|
Serial.println(errorMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lcd.setCursor(0, 1);
|
ambientTemperature = celsiusToFahrenheit(ambientTemperature);
|
||||||
lcd.print(" 4:");
|
feelsLikeTemperature = heatIndex(ambientTemperature, ambientHumidity);
|
||||||
lcd.print(massConcentrationPm4p0);
|
}
|
||||||
|
|
||||||
lcd.setCursor(8, 1);
|
if (currentTime - lcdTime >= 500) {
|
||||||
lcd.print("10:");
|
lcdTime = currentTime;
|
||||||
lcd.print(massConcentrationPm10p0);
|
|
||||||
} else {
|
|
||||||
lcd.setCursor(0, 0);
|
|
||||||
lcd.print("t:");
|
|
||||||
lcd.print(round(ambientTemperature));
|
|
||||||
|
|
||||||
lcd.setCursor(8, 0);
|
lcd.clear();
|
||||||
lcd.print("h:");
|
|
||||||
lcd.print(round(ambientHumidity));
|
|
||||||
|
|
||||||
lcd.setCursor(0, 1);
|
if (isStandardValues) {
|
||||||
lcd.print("f:");
|
lcd.setCursor(0, 0);
|
||||||
lcd.print(round(feelsLikeTemperature));
|
lcd.print("t:");
|
||||||
|
lcd.print(round(ambientTemperature));
|
||||||
|
|
||||||
lcd.setCursor(8, 1);
|
lcd.setCursor(8, 0);
|
||||||
lcd.print("v:");
|
lcd.print("h:");
|
||||||
lcd.print(vocIndex, 0);
|
lcd.print(round(ambientHumidity));
|
||||||
|
|
||||||
|
lcd.setCursor(0, 1);
|
||||||
|
lcd.print("f:");
|
||||||
|
lcd.print(round(feelsLikeTemperature));
|
||||||
|
|
||||||
|
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