[SIMPLE PROGRAM] HYT humidity & temp sensor polling / showing received data at TFT with capacitive touchscreen
Dependencies: FT800_2 HYT mbed
HYT humidity and temperature sensor polling & showing received data at TFT via graphical controller FT800/FT801.
Hardware
- HYT-271 / HYT-221 / HYT-939 humidity and temperature sensor by IST-AG
- TFT module uxTouch by Riverdi
- Break Out Board 20 by Riverdi
- Any mbed platform with I2C interface, SPI interface and 2 free GPIO for PD and INT signals
For documentation on the FT800 library, please refer to the library pages.
Connection
MCU-board to TFT-module
MCU-board is connected to TFT-module via Break Out Board. You need 6 signals to connect: SCK, MOSI and MISO are connected to a SPI channel, SS is the chip select signal, PD work as powerdown and INT for interrupts from TFT to MCU.
You have to connect VDD to BLVDD at Break Out Board if you use the board:
MCU-board to HYT sensor
MCU-board is connected to sensor via I2C. Remember to use pull-up resisrors there:

Подробнее в статьях Как перестать бояться и полюбить mbed [Часть 1 - 5] на https://habrahabr.ru/users/uuuulala/topics/
Revision 0:1f5444f2977d, committed 2016-09-26
- Comitter:
- Ksenia
- Date:
- Mon Sep 26 15:39:09 2016 +0000
- Child:
- 1:e20b5da0c912
- Commit message:
- Initial commit;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FT800_2.lib Mon Sep 26 15:39:09 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/dreschpe/code/FT800_2/#16e22c789f7d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HYT.lib Mon Sep 26 15:39:09 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/Ksenia/code/HYT/#cb02bfe8cf44
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT/display.Calibration.cpp Mon Sep 26 15:39:09 2016 +0000
@@ -0,0 +1,12 @@
+#include "display.h"
+
+/**************************************************************************************************************************
+************************** Put calibration data to FT800 ******************************************************************
+**************************************************************************************************************************/
+void Display::Calibration()
+{
+ char calibration[25] = {98, 99, 0, 0, 182, 254, 255, 255, 245, 142, 248, 255, 117, 254, 255, 255, 34, 98, 0, 0, 123, 154, 248, 255};
+ for (int i = 0; i < 24; i++) {
+ (*_TFT).Wr8(REG_TOUCH_TRANSFORM_A + i, calibration[i]);
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT/display.DisplayListFunctions.cpp Mon Sep 26 15:39:09 2016 +0000
@@ -0,0 +1,27 @@
+#include "display.h"
+
+/**************************************************************************************************************************
+************************** Start display list *****************************************************************************
+**************************************************************************************************************************/
+void Display::StartDL()
+{
+ (*_TFT).DLstart();
+ // set white color for background
+ (*_TFT).DL(CLEAR_COLOR_RGB(255, 255, 255));
+ // clear buffers for preset values
+ (*_TFT).DL(CLEAR(1, 1, 1));
+}
+
+/**************************************************************************************************************************
+************************** Finish display list ****************************************************************************
+**************************************************************************************************************************/
+void Display::FinishDL()
+{
+ (*_TFT).DL(DISPLAY());
+ // Swap the current display list
+ (*_TFT).Swap();
+ // Download the command list into fifo TFT
+ (*_TFT).Flush_Co_Buffer();
+ // Wait for the complete consumption of FT800 Coprocessor commands
+ (*_TFT).WaitCmdfifo_empty();
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT/display.Draw_CurrentValuesGraphs.cpp Mon Sep 26 15:39:09 2016 +0000
@@ -0,0 +1,163 @@
+#include "display.h"
+
+/**************************************************************************************************************************
+************************** Display real-time humidity *********************************************************************
+**************************************************************************************************************************/
+void Display::CurrentHumidity(float humidity)
+{
+ // accelerator for x-axis data output
+ char accelerator = 6;
+ // create string including current humididty and " %"
+ CreateStringTempHum(humidityStr, humidity, 0);
+ // write the new scalable (* 1.5) data to the next available array position
+ currentHumidity_Y[currentHumidity_X] = (char)(humidity * 1.5);
+
+ // start FT800 display list
+ StartDL();
+
+ // draw bottom color for graph line
+ (*_TFT).DL(COLOR_RGB(200, 200, 200));
+ (*_TFT).DL(BEGIN(EDGE_STRIP_B));
+ for (int i = 0; i < 68; i++) {
+ if (currentHumidity_Y[i] != 0 && i <= currentHumidity_X) {
+ (*_TFT).DL(VERTEX2F((i * accelerator + 15) * 16, (220 - currentHumidity_Y[i]) * 16));
+ }
+ }
+
+ // draw horisontal grid for humidity (0 .. 100)
+ HorisontalGrid_CurrentHumidity();
+
+ // draw main graph line
+ (*_TFT).DL(COLOR_RGB(9, 0, 63));
+ (*_TFT).DL(BEGIN(POINTS));
+ (*_TFT).DL(POINT_SIZE(25));
+ for (int i = 0; i < 68; i++) {
+ if (currentHumidity_Y[i] != 0 && (i < currentHumidity_X || i >= currentHumidity_X + 13)) {
+ (*_TFT).DL(VERTEX2F((i * accelerator + 15) * 16, (222 - currentHumidity_Y[i]) * 16));
+ }
+ }
+
+ // draw subtitle for main graph line
+ (*_TFT).DL(COLOR_RGB(255, 255, 255));
+ (*_TFT).DL(BEGIN(RECTS));
+ (*_TFT).DL(VERTEX2II((currentHumidity_X * accelerator + 40) + 25, (200 - currentHumidity_Y[currentHumidity_X]), 0, 0));
+ (*_TFT).DL(VERTEX2II((currentHumidity_X * accelerator + 40), (177 - currentHumidity_Y[currentHumidity_X]), 0, 0));
+ (*_TFT).DL(COLOR_RGB(255, 0, 0));
+ (*_TFT).Text((currentHumidity_X * accelerator + 30), (180 - currentHumidity_Y[currentHumidity_X] - 7), 28, 0, humidityStr);
+ (*_TFT).DL(BEGIN(LINES));
+ (*_TFT).DL(LINE_WIDTH(8));
+ (*_TFT).DL(VERTEX2F((currentHumidity_X * accelerator + 15) * 16, (220 - currentHumidity_Y[currentHumidity_X]) * 16));
+ (*_TFT).DL(VERTEX2F((currentHumidity_X * accelerator + 35) * 16, (200 - currentHumidity_Y[currentHumidity_X]) * 16));
+ (*_TFT).DL(COLOR_RGB(255, 30, 33));
+ (*_TFT).DL(BEGIN(POINTS));
+ (*_TFT).DL(POINT_SIZE(33));
+ (*_TFT).DL(VERTEX2F((currentHumidity_X * accelerator + 15) * 16, (220 - currentHumidity_Y[currentHumidity_X]) * 16));
+ (*_TFT).DL(END());
+
+ // write main title
+ (*_TFT).DL(COLOR_RGB(0, 0, 0));
+ (*_TFT).Text(15, 15, 30, 0, "Current humidity, rH");
+
+ // clean the space under the plot, create link to the main menu
+ (*_TFT).DL(SCISSOR_XY(15, 222));
+ (*_TFT).DL(SCISSOR_SIZE(420, 53));
+ (*_TFT).Gradient(0, 256, 0xFFFFFF, 450, 16, 0xFFFFFF);
+ MainMenuReference();
+
+ // finish FT801 display list
+ FinishDL();
+
+ // manage the index for array
+ if (currentHumidity_X >= 68) {
+ currentHumidity_X = 0;
+ } else {
+ currentHumidity_X ++;
+ }
+ if (pressedButton == MENU_PRESS) {
+ for (int i = 0; i < 68; i++) {
+ currentHumidity_Y[i] = 0;
+ currentHumidity_X = 0;
+ }
+ }
+}
+
+/**************************************************************************************************************************
+************************** Display real-time temperature ******************************************************************
+**************************************************************************************************************************/
+void Display::CurrentTemperature(float temperature)
+{
+ // accelerator for x-axis data output
+ char accelerator = 6;
+ // create string including current temperature with decimal mark and " С"
+ CreateStringTempHum(temperatureStr, temperature, 1);
+ // write the new scalable (* 0.88 + 45) data to the next available array position
+ currentTemperature_Y[currentTemperature_X] = (char)(temperature * 0.88 + 45);
+
+ // start FT800 display list
+ StartDL();
+
+ // draw bottom color for graph line
+ (*_TFT).DL(COLOR_RGB(200, 177, 199));
+ (*_TFT).DL(BEGIN(EDGE_STRIP_B));
+ for (int i = 0; i < 68; i++) {
+ if (currentTemperature_Y[i] != 0 && i <= currentTemperature_X) {
+ (*_TFT).DL(VERTEX2F((i * accelerator + 15) * 16, (220 - currentTemperature_Y[i]) * 16));
+ }
+ }
+
+ // draw horisontal grid for temperature (-50 .. +125)
+ HorisontalGrid_CurrentTemp();
+
+ // draw main graph line
+ (*_TFT).DL(COLOR_RGB(9, 0, 63));
+ (*_TFT).DL(BEGIN(POINTS));
+ (*_TFT).DL(POINT_SIZE(25));
+ for (int i = 0; i < 68; i++) {
+ if (currentTemperature_Y[i] != 0 && (i < currentTemperature_X || i >= currentTemperature_X + 13)) {
+ (*_TFT).DL(VERTEX2F((i * accelerator + 15) * 16, (222 - currentTemperature_Y[i]) * 16));
+ }
+ }
+
+ // draw subtitle for main graph line
+ (*_TFT).DL(COLOR_RGB(255, 255, 255));
+ (*_TFT).DL(BEGIN(RECTS));
+ (*_TFT).DL(VERTEX2II((currentTemperature_X * accelerator + 40) + 25, (200 - currentTemperature_Y[currentTemperature_X]), 0, 0));
+ (*_TFT).DL(VERTEX2II((currentTemperature_X * accelerator + 40), (177 - currentTemperature_Y[currentTemperature_X]), 0, 0));
+ (*_TFT).DL(COLOR_RGB(255, 0, 0));
+ (*_TFT).Text((currentTemperature_X * accelerator + 25), (173 - currentTemperature_Y[currentTemperature_X]), 28, 0, temperatureStr);
+ (*_TFT).DL(BEGIN(LINES));
+ (*_TFT).DL(LINE_WIDTH(8));
+ (*_TFT).DL(VERTEX2F((currentTemperature_X * accelerator + 15) * 16, (220 - currentTemperature_Y[currentTemperature_X]) * 16));
+ (*_TFT).DL(VERTEX2F((currentTemperature_X * accelerator + 35) * 16, (200 - currentTemperature_Y[currentTemperature_X]) * 16));
+ (*_TFT).DL(COLOR_RGB(255, 30, 33));
+ (*_TFT).DL(BEGIN(POINTS));
+ (*_TFT).DL(POINT_SIZE(33));
+ (*_TFT).DL(VERTEX2F((currentTemperature_X * accelerator + 15) * 16, (220 - currentTemperature_Y[currentTemperature_X]) * 16));
+ (*_TFT).DL(END());
+
+ // write main title
+ (*_TFT).DL(COLOR_RGB(0, 0, 0));
+ (*_TFT).Text(15, 15, 30, 0, "Current temperature");
+
+ // clean the space under the plot, create link to the main menu
+ (*_TFT).DL(SCISSOR_XY(15, 225));
+ (*_TFT).DL(SCISSOR_SIZE(420, 53));
+ (*_TFT).Gradient(0, 256, 0xFFFFFF, 450, 16, 0xFFFFFF);
+ MainMenuReference();
+
+ // finish FT801 display list
+ FinishDL();
+
+ // manage the index for array
+ if (currentTemperature_X >= 68) {
+ currentTemperature_X = 0;
+ } else {
+ currentTemperature_X ++;
+ }
+ if (pressedButton == MENU_PRESS) {
+ for (int i = 0; i < 68; i++) {
+ currentTemperature_Y[i] = 0;
+ currentTemperature_X = 0;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT/display.Draw_Grids.cpp Mon Sep 26 15:39:09 2016 +0000
@@ -0,0 +1,41 @@
+#include "display.h"
+
+/**************************************************************************************************************************
+************************** Draw horisontal grid for temperature (-50 .. +125) *********************************************
+**************************************************************************************************************************/
+void Display::HorisontalGrid_CurrentTemp()
+{
+ (*_TFT).DL(COLOR_RGB(20, 20, 20));
+ char gridNumb = 125 + 50;
+ for (int i = 70 * 16; i <= 225 * 16; i += 352) {
+ (*_TFT).DL(BEGIN(LINES));
+ (*_TFT).DL(LINE_WIDTH(8));
+ (*_TFT).DL(VERTEX2F(15 * 16, i));
+ (*_TFT).DL(VERTEX2F(423 * 16, i));
+ if (gridNumb >= 50) {
+ (*_TFT).Number(435, i/16 - 9, 26, 0, gridNumb - 50);
+ } else if (gridNumb == 25) {
+ (*_TFT).Text(435, i/16 - 9, 26, 0, "-25");
+ } else if (gridNumb == 0) {
+ (*_TFT).Text(435, i/16 - 9, 26, 0, "-50");
+ }
+ gridNumb = gridNumb - 25;
+ }
+}
+
+/**************************************************************************************************************************
+************************** Draw horisontal grid for humidity (0 .. 100) ***************************************************
+**************************************************************************************************************************/
+void Display::HorisontalGrid_CurrentHumidity()
+{
+ (*_TFT).DL(COLOR_RGB(20, 20, 20));
+ char gridNumb = 100;
+ for (int i = 70 * 16; i <= 220 * 16; i += 600) {
+ (*_TFT).DL(BEGIN(LINES));
+ (*_TFT).DL(LINE_WIDTH(8));
+ (*_TFT).DL(VERTEX2F(15 * 16, i));
+ (*_TFT).DL(VERTEX2F(423 * 16, i));
+ (*_TFT).Number(435, i/16 - 9, 26, 0, gridNumb);
+ gridNumb = gridNumb - 25;
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT/display.Draw_MainMenu.cpp Mon Sep 26 15:39:09 2016 +0000
@@ -0,0 +1,53 @@
+#include "display.h"
+
+/**************************************************************************************************************************
+************************** Display Main Menu ******************************************************************************
+**************************************************************************************************************************/
+void Display::MainMenu(float humidity, float temperature)
+{
+ // start FT800 display list
+ StartDL();
+
+ // write main title
+ (*_TFT).DL(COLOR_RGB(0, 0, 0));
+ (*_TFT).Text(11, 15, 30, 0, "HYT-271 sensor from IST");
+
+ // create blue rectangle with current humididty including
+ // rectangle is tagged as CURR_HUM_PRESS
+ (*_TFT).DL(TAG_MASK(1));
+ (*_TFT).DL(TAG(CURR_HUM_PRESS));
+ (*_TFT).DL(COLOR_RGB(9, 0, 63));
+ // if rectangle is already pressed, draw it with lighter color
+ if (pressedButton == CURR_HUM_PRESS) {
+ (*_TFT).DL(COLOR_RGB(75, 70, 108));
+ }
+ (*_TFT).DL(BEGIN(RECTS));
+ (*_TFT).DL(VERTEX2II(12, 62, 0, 0));
+ (*_TFT).DL(VERTEX2II(12 + 400, 62 + 93, 0, 0));
+ (*_TFT).DL(COLOR_RGB(255, 255, 255));
+ (*_TFT).Text(12 + 10, 62 + 5, 30, 0, "Current humidity (rH)");
+ CreateStringTempHum(humidityStr, humidity, 0);
+ (*_TFT).Text(12 + 10, 62 + 45, 31, 0, humidityStr);
+ (*_TFT).DL(TAG_MASK(0));
+
+ // create blue rectangle with current temperature including
+ // rectangle is tagged as CURR_TEMP_PRESS
+ (*_TFT).DL(TAG_MASK(1));
+ (*_TFT).DL(TAG(CURR_TEMP_PRESS));
+ (*_TFT).DL(COLOR_RGB(9, 0, 63));
+ // if rectangle is already pressed, draw it with lighter color
+ if (pressedButton == CURR_TEMP_PRESS) {
+ (*_TFT).DL(COLOR_RGB(75, 70, 108));
+ }
+ (*_TFT).DL(BEGIN(RECTS));
+ (*_TFT).DL(VERTEX2II(12, 62 + 93 + 12, 0, 0));
+ (*_TFT).DL(VERTEX2II(12 + 400, 62 + 93 + 12 + 93, 0, 0));
+ (*_TFT).DL(COLOR_RGB(255, 255, 255));
+ (*_TFT).Text(12 + 10, 62 + 93 + 12 + 5, 30, 0, "Current temperature");
+ CreateStringTempHum(temperatureStr, temperature, 1);
+ (*_TFT).Text(12 + 10, 62 + 93 + 12 + 45, 31, 0, temperatureStr);
+ (*_TFT).DL(TAG_MASK(0));
+
+ // finish FT800 display list
+ FinishDL();
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT/display.Draw_MainMenuReference.cpp Mon Sep 26 15:39:09 2016 +0000
@@ -0,0 +1,17 @@
+#include "display.h"
+
+/**************************************************************************************************************************
+************************** Draw link to the main menu screen **************************************************************
+**************************************************************************************************************************/
+void Display::MainMenuReference()
+{
+ (*_TFT).DL(COLOR_RGB(0, 0, 0));
+ (*_TFT).DL(TAG_MASK(1));
+ (*_TFT).DL(TAG(MENU_PRESS));
+ (*_TFT).Text(14, 240, 22, 0, "Back to main menu");
+ (*_TFT).DL(BEGIN(LINES));
+ (*_TFT).DL(LINE_WIDTH(8));
+ (*_TFT).DL(VERTEX2F(15 * 16, 260 * 16));
+ (*_TFT).DL(VERTEX2F(155 * 16, 260 * 16));
+ (*_TFT).DL(TAG_MASK(0));
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT/display.GetTouch.cpp Mon Sep 26 15:39:09 2016 +0000
@@ -0,0 +1,9 @@
+#include "display.h"
+
+/**************************************************************************************************************************
+************************** Put calibration data to FT800 ******************************************************************
+**************************************************************************************************************************/
+char Display::GetTouch()
+{
+ return (*_TFT).Rd8(REG_TOUCH_TAG);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT/display.StringsTransforming.cpp Mon Sep 26 15:39:09 2016 +0000
@@ -0,0 +1,51 @@
+#include "display.h"
+
+/**************************************************************************************************************************
+************************** Transform humiditity / temperature float value to string ***************************************
+**************************************************************************************************************************/
+// If isTemp = 0, string includes
+// 1. current humididty
+// 3. " %"
+
+// If isTemp = 1, string includes
+// 1. "-" (optional),
+// 2. current temperature with decimal mark
+// 3. " С"
+void Display::CreateStringTempHum(char *str, float number, bool isTemp)
+{
+ short int multipedNumber = (short int)(number * 100);
+ char strCnt = 0;
+ if (isTemp) {
+ if (multipedNumber < 0) {
+ multipedNumber = -multipedNumber;
+ str[strCnt] = '-';
+ strCnt++;
+ }
+ }
+ if (multipedNumber >= 10000) {
+ str[strCnt] = '0' + (multipedNumber % 100000) / 10000;
+ strCnt++;
+ }
+ if (multipedNumber >= 1000) {
+ str[strCnt] = '0' + (multipedNumber % 10000) / 1000;
+ strCnt++;
+ }
+ if (multipedNumber >= 100) {
+ str[strCnt] = '0' + (multipedNumber % 1000) / 100;
+ strCnt++;
+ }
+ if (isTemp) {
+ str[strCnt] = '.';
+ strCnt++;
+ str[strCnt] = '0' + (multipedNumber % 100) / 10;
+ strCnt++;
+ str[strCnt] = ' ';
+ strCnt++;
+ str[strCnt] = 'C';
+ strCnt++;
+ } else {
+ str[strCnt] = '%';
+ strCnt++;
+ }
+ str[strCnt] = 0;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/display.h Mon Sep 26 15:39:09 2016 +0000
@@ -0,0 +1,71 @@
+#include "mbed.h"
+#include "FT_Platform.h"
+#include <string>
+
+#ifndef DISPLAY_H_
+#define DISPLAY_H_
+
+/**************************************************************************************************************************
+************************** Defines using for drawing **********************************************************************
+**************************************************************************************************************************/
+
+// all tracking touch screen areas
+typedef enum {
+ NONE_PRESS,
+ CURR_TEMP_PRESS,
+ CURR_HUM_PRESS,
+ MENU_PRESS,
+} pressValues;
+
+// all existing screens
+typedef enum {
+ MENU_SCREEN,
+ CURR_HUM_SCREEN,
+ CURR_TEMP_SCREEN,
+} screenValues;
+
+
+/**************************************************************************************************************************
+************************** User class for drawing at FT800 ****************************************************************
+**************************************************************************************************************************/
+
+class Display
+{
+public:
+ // in Display class we use FT800 TFT (definition is available in main.cpp)
+ Display(FT800 *TFT) {
+ _TFT = TFT;
+ }
+
+ // functions describing all available screens (screens-functions)
+ void MainMenu(float humidity, float temperature); // [display.Draw_MainMenu.cpp]
+ void CurrentHumidity(float humidity); // [display.Draw_CurrentValuesGraphs.cpp]
+ void CurrentTemperature(float temperature); // [display.Draw_CurrentValuesGraphs.cpp]
+
+ // functions using to prepare FT800
+ void Calibration(void); // [display.Calibration.cpp]
+
+ // functions for touch screen tracking
+ char GetTouch(void); // [display.GetTouch.cpp]
+
+ // variables using for navigation between screens
+ char pressedButton;
+ char activeScreen;
+
+private:
+ FT800 *_TFT;
+
+ void StartDL(void); // [display.DisplayListFunctions.cpp]
+ void FinishDL(void); // [display.DisplayListFunctions.cpp]
+ void MainMenuReference(void); // [display.Draw_MainMenuReference.cpp]
+ void HorisontalGrid_CurrentTemp(void); // [display.Draw_Grids.cpp]
+ void HorisontalGrid_CurrentHumidity(void); // [display.Draw_Grids.cpp]
+
+ void CreateStringTempHum(char *str, float number, bool isTemp); // [display.StringsTransforming.cpp]
+
+ char humidityStr[8], temperatureStr[8];
+ char currentHumidity_X, currentTemperature_X;
+ char currentHumidity_Y[68], currentTemperature_Y[68];
+};
+
+#endif /* SCREENS_H_ */
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Sep 26 15:39:09 2016 +0000
@@ -0,0 +1,73 @@
+#include "mbed.h"
+#include "FT_Platform.h"
+#include "HYT.h"
+#include "display.h"
+
+HYT SENSOR (PD6, PD7); // sda, scl [SLSTK3400A]
+FT800 TFT (PE10, PE11, PE12, PE13, PB11, PD4); // mosi, miso, sck, ss, int, pd [SLSTK3400A]
+//HYT SENSOR (D14, D15); // sda, scl [WIZwiki-W7500P]
+//FT800 TFT (D11, D12, D13, D10, D9, D8); // mosi, miso, sck, ss, int, pd [WIZwiki-W7500P]
+//HYT SENSOR (PA08, PA09); // sda, scl [ATSAMD21-XPRO]
+//FT800 TFT (PA18, PA16, PA19, PA17, PA20, PA21); // mosi, miso, sck, ss, int, pd [ATSAMD21-XPRO]
+
+Display disp(&TFT);
+
+/**************************************************************************************************************************
+************************** HYT sensor polling cycle ***********************************************************************
+**************************************************************************************************************************/
+void dataUpdate(void)
+{
+ SENSOR.MRCommand();
+ wait_ms(100);
+ SENSOR.DFCommand();
+}
+
+/**************************************************************************************************************************
+************************** Main function **********************************************************************************
+**************************************************************************************************************************/
+int main()
+{
+ disp.Calibration();
+
+ disp.activeScreen = MENU_SCREEN;
+ disp.pressedButton = NONE_PRESS;
+
+ // change active screen depending on pressed area
+ while(1) {
+ dataUpdate();
+ disp.pressedButton = disp.GetTouch();
+
+ // ----------------------------------------------------------------------------------------------
+ // Main menu screen
+ if (disp.activeScreen == MENU_SCREEN) {
+ disp.MainMenu(SENSOR.humidity, SENSOR.temperature);
+ if (disp.pressedButton) {
+ wait_ms(150);
+ if (disp.pressedButton == CURR_TEMP_PRESS) {
+ disp.activeScreen = CURR_TEMP_SCREEN;
+ } else if (disp.pressedButton == CURR_HUM_PRESS) {
+ disp.activeScreen = CURR_HUM_SCREEN;
+ }
+ disp.pressedButton = NONE_PRESS;
+ }
+
+ // ----------------------------------------------------------------------------------------------
+ // Any other screen
+ } else {
+ // ----------------------------------------------------------------------------------------------
+ // You can back to main menu from any screen
+ if (disp.pressedButton == MENU_PRESS) {
+ disp.pressedButton = NONE_PRESS;
+ disp.activeScreen = MENU_SCREEN;
+ } else {
+ // ----------------------------------------------------------------------------------------------
+ // Screen with current temperature / humidity
+ if (disp.activeScreen == CURR_TEMP_SCREEN) {
+ disp.CurrentTemperature(SENSOR.temperature);
+ } else if (disp.activeScreen == CURR_HUM_SCREEN) {
+ disp.CurrentHumidity(SENSOR.humidity);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Sep 26 15:39:09 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34 \ No newline at end of file