This demonstrates some of the capabilities of the MAX44000. It is written to work with the ARD2PMD adapter board and the MAX44000PMB1. It uses the standard Arduino pin names and will compile for most Arduino form-factor mbed boards.

Dependencies:   ard2pmod mbed

This demonstrates some of the capabilities of the MAX44000.

This is written to work with the ARD2PMD adapter board and the MAX44000PMB1. It uses the standard Arduino pin names and it will compile for most Arduino form-factor mbed boards.

Some boards use D13 for an LED signal, so this example uses the second row (row B, pins 7 through 12) of the Pmod connector.

  • LED1 toggles when something is first detected by the proximity sensor.
  • LED2 indicates when the Ambient Light Sensor reads grater than alsLim.
  • LED3 will stay on whenever something is detected by the proximity sensor and stay on for an additional 5s after it is no longer detected.

The following boards have been tested to work:

  • MAX32600MBED
  • FRDM-KL25Z
  • FRDM-K64F
  • Seeeduino Arch (LEDs inverted)
  • Seeeduino Arch Pro
  • ST Nucleo F401RE (only one LED, inverted)
Revision:
2:405cc6627ffb
Parent:
1:03aeb304d3b3
Child:
3:61cc32322303
--- a/main.cpp	Sun Jun 22 23:04:51 2014 +0000
+++ b/main.cpp	Mon Jun 23 05:03:54 2014 +0000
@@ -1,13 +1,32 @@
+/* MAX44000 Ambient Light Sensor / Proximity Sensor Demo
+ * This demonstrates some of the capabilities of the MAX44000.
+ * 
+ * This is written to work with the ARD2PMD adapter board and 
+ * the MAX44000PMB1.  It uses the standard Arduino pin names 
+ * and it will compile for most arduino form-factor mbed boards.
+ *
+ * LED1 toggles when something is first detected by the proximity sensor.
+ * LED2 indicates when the Ambient Light Sensor reads grater than alsLim.
+ * LED3 will stay on whenever something is detected by the proximity sensor 
+ *   and stay on for an additional 5s after it is no longer detected.
+ *
+ * The following boards have been tested to work:
+ *   FRDM-KL25Z, FRDM-K64F
+ *   Seeeduino Arch and Arch Pro (LEDs inverted)
+ *   ST Nucleo F401RE (only one LED)
+ *  
+ * Some boards use D13 for an LED signal, so this example uses the second 
+ *   row (row B, pins 7 through 12) of the Pmod connector.  
+ */
+
 #include "mbed.h"
 #include "MAX14661.h"
 
 MAX14661 mux(D14, D15);
 I2C i2c(D14, D15);
-DigitalOut r(LED1);
-DigitalOut g(LED2);
-DigitalOut b(LED3);
-//DigitalIn pa3(D12);  // Set as input to remove load from PA3
-//DigitalIn pa4(D13);  // Set as input to remove load from PA4
+DigitalOut tog(LED1);
+DigitalOut als(LED2);
+DigitalOut dly(LED3);
 DigitalIn pb3(D6);  // Set as input to remove load from PB3
 DigitalIn pb4(D7);  // Set as input to remove load from PB4
 
@@ -18,12 +37,7 @@
 {
     char cmd[2];
 
-/*    //  SDA(D14) + PA4(D13) + PB4(D7)  ,  SCL(D15) + PA3(D12) + PB3(D6)
-    mux.setAB((MAX14661::SW10 | MAX14661::SW11 | MAX14661::SW08),
-              (MAX14661::SW09 | MAX14661::SW12 | MAX14661::SW07));
-*/
-
-    //           SDA (D14)   +   PB4 (D7)         SCL (D15)   +   PB3 (D6)
+    //  SDA (D14) + PB4 (D7)     SCL (D15) + PB3 (D6)
     mux.setAB((MAX14661::SW10 | MAX14661::SW08),
               (MAX14661::SW09 | MAX14661::SW07));
 
@@ -41,31 +55,31 @@
 
     bool lastProx = false;
     int offDelay = 0;
-    r = false;
-    g = false;
-    b = false;
+    tog = false;
+    als = false;
+    dly = false;
 
     while (true) {
         wait (0.02);
         cmd[0] = 0x04; // ALS Data Register
         i2c.write(alsAddr, cmd, 1);
         i2c.read(alsAddr, cmd, 1);
-        g = (cmd[0] < alsLim);
+        als = (cmd[0] < alsLim);
 
         cmd[0] = 0x16; // Prox Data Register
         i2c.write(alsAddr, cmd, 1);
         i2c.read(alsAddr, cmd, 1);
         if (cmd[0]) {
             if (!lastProx) {
-                r = !r;
+                tog = !tog;
             }
             lastProx = true;
             offDelay = 250;
-            b = false;
+            dly = false;
         } else {
             lastProx = false;
         }
         if (offDelay > 0) { offDelay -= 1; }
-        else { b = true; }
+        else { dly = true; }
     }
 }
\ No newline at end of file