Venkata Siva Krishna Madala / Mbed 2 deprecated ECE4180FinalProjectFall22

Dependencies:   4DGL-uLCD-SE ENS160_Library mbed PinDetect mbed-rtos

main.cpp

Committer:
krishnamvs
Date:
2022-12-06
Revision:
10:112572fbb168
Parent:
8:31e63caf37e2
Child:
11:03f86b377280

File content as of revision 10:112572fbb168:

#include "mbed.h"
#include "ens160_i2c.h"
#include "uLCD_4DGL.h"

ENS160 myENS(p9, p10, ENS160_ADDRESS_HIGH);
DigitalOut myled(LED1);
Serial pc(USBTX, USBRX);
uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin;

bool printedCompensation = false; 
int ensStatus; 

float rh;
float tempC; 

int main()
{
    if (!myENS.init())
    {
        pc.printf("Hello, ENS160! Reading raw data from registers...\n");
        while(1);
    }
    if( myENS.setOperatingMode(SFE_ENS160_RESET) )
        pc.printf("Ready.\n");
    wait(0.1);
    myENS.setOperatingMode(SFE_ENS160_IDLE);
    wait(0.5);
    myENS.setOperatingMode(SFE_ENS160_STANDARD);
    ensStatus = myENS.getFlags();
    pc.printf("Gas Sensor Status Flag: ");
    pc.printf("%d\n", ensStatus);
    while (1)
    {
        if( myENS.checkDataStatus() )
        {
            if( printedCompensation == false)
            {
                pc.printf("---------------------------\n");
                pc.printf("Compensation Temperature: ");
                pc.printf("%f\n", myENS.getTempCelsius());
                pc.printf("---------------------------");
                pc.printf("Compensation Relative Humidity: ");
                pc.printf("%f\n", myENS.getRH());
                pc.printf("---------------------------\n");
                printedCompensation = true;
                wait(0.5);
            }

            pc.printf("Air Quality Index (1-5) : ");
            pc.printf("%d\n", myENS.getAQI());

            pc.printf("Total Volatile Organic Compounds: ");
            pc.printf("%d", myENS.getTVOC());
            pc.printf("ppb\n");

            pc.printf("CO2 concentration: ");
            pc.printf("%d", myENS.getECO2());
            pc.printf("ppm\n");

        }
        wait(0.1);
        }
}