Very simple SW polling HYT humidity & temp sensor and show received data at TFT [NO TOUCHSCREEN USED]

Dependencies:   FT800_2 HYT mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "FT_Platform.h"
00003 #include "HYT.h"
00004 
00005 /***********************************************************************************************************************/
00006 /* Declare and initialize FTDI FT800 controller according to SPI lines connected */
00007  
00008 //// SLSTK3400A
00009 HYT SENSOR (PD6, PD7); // sda, scl
00010 FT800 TFT (PE10, PE11, PE12, PE13, PB11, PD4); // mosi, miso, sck, ss, int, pd
00011 
00012 //// WIZwiki-W7500P
00013 //HYT SENSOR (D14, D15); // sda, scl
00014 //FT800 TFT (D11, D12, D13, D10, D9, D8); // mosi, miso, sck, ss, int, pd
00015 
00016 // ATSAMD21-XPRO
00017 //HYT SENSOR (PA08, PA09); // sda, scl
00018 //FT800 TFT (PA18, PA16, PA19, PA17, PA20, PA21); // mosi, miso, sck, ss, int, pd
00019 
00020 
00021 /***********************************************************************************************************************/
00022 /* HYT sensor polling cycle */
00023 void dataUpdate(void)
00024 {
00025     SENSOR.MRCommand();
00026     wait_ms(100);
00027     SENSOR.DFCommand();
00028 }
00029 
00030 /***********************************************************************************************************************/
00031 /* Construct the screen and downloasd it to the TFT */
00032 void drawTimeScreen(void)
00033 {
00034     // start FT800 display list
00035     TFT.DLstart();
00036     TFT.DL(CLEAR_COLOR_RGB(255, 255, 255));
00037     TFT.DL(CLEAR(1, 1, 1));
00038 
00039     TFT.DL(COLOR_RGB(0, 0, 0));
00040     TFT.Text(11, 15, 30, 0, "Demo-project for habrahabr.ru");
00041     TFT.Text(13, 15 + 40, 28, 0, "Using FT800 library and HYT library");
00042 
00043     TFT.DL(COLOR_RGB(9, 40, 3));
00044     TFT.DL(BEGIN(RECTS));
00045     TFT.DL(VERTEX2II(11, 105, 0, 0));
00046     TFT.DL(VERTEX2II(11 + 222, 105 + 100, 0, 0));
00047 
00048     TFT.DL(COLOR_RGB(255, 255, 255));
00049     TFT.Text(11 + 10, 105 + 10, 28, 0, "Relative humidity, %");
00050     TFT.Number(11 + 10, 105 + 10 + 30, 31, 0, SENSOR.humidity);
00051 
00052     TFT.DL(COLOR_RGB(9, 3, 40));
00053     TFT.DL(BEGIN(RECTS));
00054     TFT.DL(VERTEX2II(11 + 222 + 14, 105, 0, 0));
00055     TFT.DL(VERTEX2II(11 + 222 + 14 + 222, 105 + 100, 0, 0));
00056 
00057     TFT.DL(COLOR_RGB(255, 255, 255));
00058     TFT.Text(11 + 222 + 14 + 10, 105 + 10, 28, 0, "Temperature, C");
00059     TFT.Number(11 + 222 + 14 + 10, 105 + 10 + 30, 31, 0, SENSOR.temperature);
00060     
00061     TFT.DL(COLOR_RGB(0, 0, 0));
00062     TFT.Text(300, 105 + 100 + 35, 28, 0, "e-mail: xk@efo.ru");
00063     
00064     TFT.DL(BEGIN(LINES));
00065     TFT.DL(LINE_WIDTH(8));
00066     TFT.DL(VERTEX2II(11, 15 + 40 + 30, 0, 0));
00067     TFT.DL(VERTEX2II(460, 15 + 40 + 30, 0, 0));
00068 
00069     // finish FT800 display list
00070     TFT.DL(DISPLAY());
00071     TFT.Swap();
00072 }
00073 
00074 /***********************************************************************************************************************/
00075 /* Main function */
00076 int main()
00077 {
00078     while(1) {
00079         dataUpdate();
00080         drawTimeScreen();
00081     }
00082 }