3 Sensors

Dependencies:   BSP_DISCO_F746NG BME280

main.cpp

Committer:
inistol
Date:
2 months ago
Revision:
2:d591c13c9347
Parent:
1:bea4451dcea2

File content as of revision 2:d591c13c9347:

#include "mbed.h"
#include "stm32746g_discovery_lcd.h"
#include "stm32746g_discovery_ts.h"
#include "BME280.h"

Serial pc(USBTX, USBRX);

#if defined(TARGET_LPC1768)
 BME280 sensor(PB_9, PB_8);
#else
 BME280 sensor(I2C_SDA, I2C_SCL);
#endif
TS_StateTypeDef TS_State;

DigitalOut    MUX0(D7); // low-active
DigitalOut    MUX1(D4); 
DigitalOut    MUX2(D1); 

float x=0;
float Temp1=0;
float Temp2=0;
float Temp3=0;
float y2=0;
float z=0;
uint8_t y=0;
uint8_t text[30];
uint8_t idx;
 
int main()
{
    BSP_LCD_Init();
    BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS);
    BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
    BSP_LCD_Clear(LCD_COLOR_BLACK);
    

    while (1) {
        

        BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
        BSP_LCD_SetTextColor(LCD_COLOR_ORANGE);

        
        MUX0 = 0;
        MUX1 = 0;
        MUX2 = 0;
        
        BME280 sensor(I2C_SDA, I2C_SCL);        

        
        x = sensor.getTemperature();
        if(x<35 and x>10){
        sprintf((char*)text, "%2.2f deg C",x);
        BSP_LCD_DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, CENTER_MODE);
        }

        HAL_Delay(10);
                
        MUX0 = 1;
        MUX1 = 0;
        MUX2 = 0;
                
        BME280 sensor1(I2C_SDA, I2C_SCL); 
        
        
        y2 = sensor1.getTemperature();
        if(y2<35 and y2>10){
        Temp2 = sensor1.getTemperature();
        sprintf((char*)text, "%2.2f deg C",y2);
        BSP_LCD_DisplayStringAt(0, LINE(idx+5), (uint8_t *)&text, CENTER_MODE);
        }
        
        HAL_Delay(10);
        
        MUX0 = 0;
        MUX1 = 1;
        MUX2 = 0;
        
        BME280 sensor2(I2C_SDA, I2C_SCL); 
        
        z = sensor2.getTemperature();
        if(z<35 and z>10){
        Temp3 = sensor2.getTemperature();
        sprintf((char*)text, "%2.2f deg C",z);
        BSP_LCD_DisplayStringAt(0, LINE(idx+9), (uint8_t *)&text, CENTER_MODE);
        }
        
        HAL_Delay(10); 
        
    }
}