Industry's Lowest-Power Ambient Light Sensor with ADC

Dependents:   FYPhh FYPhh5 FYPhh5ultrafinal FYPhh5ultrafinal

Revision:
3:13e5af215b11
Parent:
2:08d850dd1cb8
--- a/MAX44009.h	Mon Sep 17 11:21:35 2018 +0000
+++ b/MAX44009.h	Mon Sep 17 11:41:33 2018 +0000
@@ -23,7 +23,103 @@
     Example:
 
 @code
+#include "mbed.h"
+#include "MAX44009.h"
 
+MAX44009 myMAX44009 ( I2C_SDA, I2C_SCL, MAX44009::MAX44009_ADDRESS_A0_VCC, 400000 );
+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 an ADC sample
+
+
+//
+// @brief   FUNCTION PROTOTYPES
+//
+void    changeDATA     ( void );
+
+
+//@brief FUNCTION FOR APPLICATION MAIN ENTRY.
+//
+int main()
+{
+    MAX44009::MAX44009_status_t       aux;
+    MAX44009::MAX44009_vector_data_t  myMAX44009_Data;
+
+    pc.baud ( 115200 );
+
+
+    myled   =   1;
+    wait(3);
+    myled   =   0;
+
+    // Configure the device: Default mode ( sample every 800ms ), CDR and TIM are automatically determined
+    aux  =   myMAX44009.MAX44009_Configuration ( MAX44009::CONFIGURATION_CONT_DEFAULT_MODE, MAX44009::CONFIGURATION_MANUAL_DEFAULT_MODE, MAX44009::CONFIGURATION_CDR_CURRENT_NOT_DIVIDED, MAX44009::CONFIGURATION_TIM_800_MS );
+
+
+    myState  =   0UL;                                                           // Reset the variable
+    newAction.attach( &changeDATA, 2 );                                         // the address of the function to be attached ( changeDATA ) and the interval ( 2s )
+
+    // Let the callbacks take care of everything
+    while(1) {
+        sleep();
+
+        if ( myState == 1UL ) {
+            myled = 1U;
+
+            // Get Lux value
+            aux  =   myMAX44009.MAX44009_GetLux                    ( MAX44009::RESOLUTION_EXTENDED_RESOLUTION, &myMAX44009_Data );
+
+            // Get current division ratio
+            aux  =   myMAX44009.MAX44009_GetCurrentDivisionRatio   ( &myMAX44009_Data );
+
+            // Get integration time
+            aux  =   myMAX44009.MAX44009_GetIntegrationTime        ( &myMAX44009_Data );
+
+            // Transmit result through the UART
+            pc.printf ( "Lux: %0.001f Lux\r\n", myMAX44009_Data.lux );
+
+
+            // 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        17/September/2018
+// @version     17/September/2018   The ORIGIN
+// @pre         N/A
+// @warning     N/A.
+//
+void changeDATA ( void )
+{
+    myState  =   1UL;
+}
 @endcode
 */
 
@@ -246,7 +342,7 @@
     /** It configures the device.
       */
     MAX44009_status_t  MAX44009_Configuration           ( MAX44009_configuration_cont_t myContinuousMode, MAX44009_configuration_manual_t myManualMode,
-                                                          MAX44009_configuration_cdr_t myCurrentRatio, MAX44009_configuration_tim_t myIntegrationTime     );
+            MAX44009_configuration_cdr_t myCurrentRatio, MAX44009_configuration_tim_t myIntegrationTime     );
 
     /** It gets the current division ratio
       */