Digital Humidity Sensor

Revision:
3:42e11b9135b5
Parent:
2:870701ee67c4
--- a/SHT3X.h	Thu Mar 25 20:24:25 2021 +0000
+++ b/SHT3X.h	Mon Apr 26 11:22:46 2021 +0000
@@ -23,7 +23,104 @@
     Example:
 
 @code
+#include "mbed.h"
+#include "SHT3X.h"
 
+SHT3X mySHT3X ( I2C_SDA, I2C_SCL, SHT3X::SHT3X_ADDRESS_B, 400000 );             // I2C_SDA | I2C_SCL
+Serial pc     ( USBTX, USBRX );                                                 // tx, rx
+
+DigitalOut  myled   ( LED1 );
+Ticker      newAction;
+
+
+//@brief Constants.
+
+
+//@brief Variables.
+volatile uint32_t myState;                                                      // State that indicates when to perform a new sample
+
+
+//@brief   FUNCTION PROTOTYPES
+void    changeDATA     ( void );
+
+
+//@brief FUNCTION FOR APPLICATION MAIN ENTRY.
+int main()
+{
+    SHT3X::SHT3X_status_t aux;
+    SHT3X::SHT3X_data_t   mySHT3X_Data;
+
+    pc.baud ( 115200 );
+
+    myled   =   1;
+    wait(3);
+    myled   =   0;
+
+    // Set a software reset
+    aux  =   mySHT3X.SHT3X_SetSoftReset ();
+    wait_ms(2U);
+
+    // Clear the STATUS register
+    aux  =   mySHT3X.SHT3X_ClearStatus ();
+
+    // Disable the Heater
+    aux  =   mySHT3X.SHT3X_SetHeater ( SHT3X::SHT3X_HEATER_DISABLE );
+
+    // Do not perform periodic measurement
+    aux  =   mySHT3X.SHT3X_SetBreakCommand ();
+
+    myState  =   0UL;                                                           // Reset the variable
+    newAction.attach( &changeDATA, 1U );                                        // the address of the function to be attached ( changeDATA ) and the interval ( 1s )
+
+    // Let the callbacks take care of everything
+    while(1) {
+        sleep();
+
+        if ( myState == 1UL ) {
+            myled = 1U;
+
+            // Trigger to get a new data set, no clock stretching and repeatibility high
+            aux  =   mySHT3X.SHT3X_OneShotTriggerAllData ( SHT3X::SHT3X_CLOCK_STRETCHING_DISABLED_REPEATABILITY_HIGH );
+            wait_ms(15U);
+
+            // Get all the data
+            aux  =   mySHT3X.SHT3X_OneShotGetAllRawData ( &mySHT3X_Data.rawData );
+
+
+            // Process all the data
+            mySHT3X.SHT3X_ProccessData ( mySHT3X_Data.rawData, &mySHT3X_Data.data );
+
+            // Send data through the UART
+            pc.printf ( "T: %0.2f C, RH: %0.2f %%\r\n", mySHT3X_Data.data.temperature, mySHT3X_Data.data.relativeHumidity );
+
+
+            // Reset the variables
+            myState  =   0UL;
+            myled    =   0U;
+        }
+    }
+}
+
+
+// @brief       changeDATA ( void  )
+//
+// @details     It changes myState variable
+//
+// @param[in]    N/A
+//
+// @param[out]   N/A.
+//
+// @return       N/A.
+//
+// @author      Manuel Caballero
+// @date        25/March/2021
+// @version     25/March/2021   The ORIGIN
+// @pre         N/A
+// @warning     N/A.
+void changeDATA ( void )
+{
+    myState  =   1UL;
+}
 @endcode
 */