KL25Z - Wi-Go kit. Demo code using ComparatorIn and TEMT6200 libraries.

Dependencies:   ComparatorIn TEMT6200 mbed

Files at this revision

API Documentation at this revision

Comitter:
frankvnk
Date:
Sun Jun 16 19:54:01 2013 +0000
Child:
1:69bec2b91d51
Commit message:
Initial release

Changed in this revision

ComparatorIn.lib Show annotated file Show diff for this revision Revisions of this file
TEMT6200.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ComparatorIn.lib	Sun Jun 16 19:54:01 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/frankvnk/code/ComparatorIn/#f340e0545b53
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TEMT6200.lib	Sun Jun 16 19:54:01 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/frankvnk/code/TEMT6200/#55136b956b17
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Jun 16 19:54:01 2013 +0000
@@ -0,0 +1,54 @@
+#include "TEMT6200.h"
+#include "ComparatorIn.h"
+#include "mbed.h"
+
+void ambi_rise(void);       // ISR callback pointer
+void ambi_fall(void);       // ISR callback pointer
+
+// RGB LED
+DigitalOut cmpled (LED_GREEN);
+DigitalOut blinky (LED_BLUE);
+
+// Ambient light sensor to comparator plus input = PTC8, min input = 12-bit DAC0
+ComparatorIn compi(PTC8, PTE30);
+
+// Ambient light sensor : PTD5 = enable, PTB0 = analog input
+TEMT6200 ambi(PTD5, PTB0);
+
+int main()
+{
+    // Ambient light detector
+    ambi.pwr(AMB_ON);
+    printf("\n- Ambient light sensor calibration.\n");
+    printf("  Make sure the sensor is obscured .\n");
+    printf("  Press any key to calibrate.\n");
+    getchar();
+    ambi.calibrate();                                 // Calibrate 
+    printf("- Calibration finished.\n");
+
+    // Comparator settings
+    compi.rising(&ambi_rise);                         // Set comparator rising int callback to ambi_rise
+    compi.falling(&ambi_fall);                        // Set comparator falling int callback to ambi_fall
+    compi.treshold(ambi.lux_pct(300.0));              // Set ISR treshold to 300lux
+    compi.int_en(1);                                  // Enable comparator interrupt
+
+    cmpled = 1;
+    
+    while (1)
+    {
+        printf("%7.2f lux\n",ambi.read());
+        wait(0.5);
+        blinky = !blinky;
+    }
+}
+
+// Comparator callback
+void ambi_rise(void)
+{
+    cmpled = 0;                       // Green led on.
+}
+
+void ambi_fall(void)
+{
+    cmpled = 1;                       // Green led off.
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Jun 16 19:54:01 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file