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)
Committer:
gsteiert
Date:
Mon Jun 23 05:30:26 2014 +0000
Revision:
3:61cc32322303
Parent:
2:405cc6627ffb
Child:
4:226ef11c3ef4
Corrected comments.  Arch Pro LEDs are not inverted.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gsteiert 2:405cc6627ffb 1 /* MAX44000 Ambient Light Sensor / Proximity Sensor Demo
gsteiert 2:405cc6627ffb 2 * This demonstrates some of the capabilities of the MAX44000.
gsteiert 2:405cc6627ffb 3 *
gsteiert 2:405cc6627ffb 4 * This is written to work with the ARD2PMD adapter board and
gsteiert 2:405cc6627ffb 5 * the MAX44000PMB1. It uses the standard Arduino pin names
gsteiert 2:405cc6627ffb 6 * and it will compile for most arduino form-factor mbed boards.
gsteiert 2:405cc6627ffb 7 *
gsteiert 2:405cc6627ffb 8 * LED1 toggles when something is first detected by the proximity sensor.
gsteiert 2:405cc6627ffb 9 * LED2 indicates when the Ambient Light Sensor reads grater than alsLim.
gsteiert 2:405cc6627ffb 10 * LED3 will stay on whenever something is detected by the proximity sensor
gsteiert 2:405cc6627ffb 11 * and stay on for an additional 5s after it is no longer detected.
gsteiert 2:405cc6627ffb 12 *
gsteiert 2:405cc6627ffb 13 * The following boards have been tested to work:
gsteiert 3:61cc32322303 14 * FRDM-KL25Z
gsteiert 3:61cc32322303 15 * FRDM-K64F
gsteiert 3:61cc32322303 16 * Seeeduino Arch (LEDs inverted)
gsteiert 3:61cc32322303 17 * Seeeduino Arch Pro
gsteiert 3:61cc32322303 18 * ST Nucleo F401RE (only one LED, inverted)
gsteiert 2:405cc6627ffb 19 *
gsteiert 2:405cc6627ffb 20 * Some boards use D13 for an LED signal, so this example uses the second
gsteiert 2:405cc6627ffb 21 * row (row B, pins 7 through 12) of the Pmod connector.
gsteiert 2:405cc6627ffb 22 */
gsteiert 2:405cc6627ffb 23
gsteiert 0:803011eae289 24 #include "mbed.h"
gsteiert 0:803011eae289 25 #include "MAX14661.h"
gsteiert 0:803011eae289 26
gsteiert 0:803011eae289 27 MAX14661 mux(D14, D15);
gsteiert 1:03aeb304d3b3 28 I2C i2c(D14, D15);
gsteiert 2:405cc6627ffb 29 DigitalOut tog(LED1);
gsteiert 2:405cc6627ffb 30 DigitalOut als(LED2);
gsteiert 2:405cc6627ffb 31 DigitalOut dly(LED3);
gsteiert 1:03aeb304d3b3 32 DigitalIn pb3(D6); // Set as input to remove load from PB3
gsteiert 1:03aeb304d3b3 33 DigitalIn pb4(D7); // Set as input to remove load from PB4
gsteiert 1:03aeb304d3b3 34
gsteiert 1:03aeb304d3b3 35 const int alsAddr = 0x94;
gsteiert 1:03aeb304d3b3 36 const char alsLim = 0x01;
gsteiert 0:803011eae289 37
gsteiert 0:803011eae289 38 int main()
gsteiert 0:803011eae289 39 {
gsteiert 1:03aeb304d3b3 40 char cmd[2];
gsteiert 1:03aeb304d3b3 41
gsteiert 2:405cc6627ffb 42 // SDA (D14) + PB4 (D7) SCL (D15) + PB3 (D6)
gsteiert 1:03aeb304d3b3 43 mux.setAB((MAX14661::SW10 | MAX14661::SW08),
gsteiert 1:03aeb304d3b3 44 (MAX14661::SW09 | MAX14661::SW07));
gsteiert 1:03aeb304d3b3 45
gsteiert 1:03aeb304d3b3 46 cmd[0] = 0x02; // Receive Register
gsteiert 1:03aeb304d3b3 47 cmd[1] = 0xFF; // 1.56ms, 128x
gsteiert 1:03aeb304d3b3 48 i2c.write(alsAddr, cmd, 2);
gsteiert 1:03aeb304d3b3 49
gsteiert 1:03aeb304d3b3 50 cmd[0] = 0x03; // Transmit Register
gsteiert 1:03aeb304d3b3 51 cmd[1] = 0x0F; // 110mA
gsteiert 1:03aeb304d3b3 52 i2c.write(alsAddr, cmd, 2);
gsteiert 1:03aeb304d3b3 53
gsteiert 1:03aeb304d3b3 54 cmd[0] = 0x01; // Config Register
gsteiert 1:03aeb304d3b3 55 cmd[1] = 0x10; // ALS/Prox Mode
gsteiert 1:03aeb304d3b3 56 i2c.write(alsAddr, cmd, 2);
gsteiert 1:03aeb304d3b3 57
gsteiert 1:03aeb304d3b3 58 bool lastProx = false;
gsteiert 1:03aeb304d3b3 59 int offDelay = 0;
gsteiert 2:405cc6627ffb 60 tog = false;
gsteiert 2:405cc6627ffb 61 als = false;
gsteiert 2:405cc6627ffb 62 dly = false;
gsteiert 1:03aeb304d3b3 63
gsteiert 1:03aeb304d3b3 64 while (true) {
gsteiert 1:03aeb304d3b3 65 wait (0.02);
gsteiert 1:03aeb304d3b3 66 cmd[0] = 0x04; // ALS Data Register
gsteiert 1:03aeb304d3b3 67 i2c.write(alsAddr, cmd, 1);
gsteiert 1:03aeb304d3b3 68 i2c.read(alsAddr, cmd, 1);
gsteiert 2:405cc6627ffb 69 als = (cmd[0] < alsLim);
gsteiert 1:03aeb304d3b3 70
gsteiert 1:03aeb304d3b3 71 cmd[0] = 0x16; // Prox Data Register
gsteiert 1:03aeb304d3b3 72 i2c.write(alsAddr, cmd, 1);
gsteiert 1:03aeb304d3b3 73 i2c.read(alsAddr, cmd, 1);
gsteiert 1:03aeb304d3b3 74 if (cmd[0]) {
gsteiert 1:03aeb304d3b3 75 if (!lastProx) {
gsteiert 2:405cc6627ffb 76 tog = !tog;
gsteiert 1:03aeb304d3b3 77 }
gsteiert 1:03aeb304d3b3 78 lastProx = true;
gsteiert 1:03aeb304d3b3 79 offDelay = 250;
gsteiert 2:405cc6627ffb 80 dly = false;
gsteiert 1:03aeb304d3b3 81 } else {
gsteiert 1:03aeb304d3b3 82 lastProx = false;
gsteiert 1:03aeb304d3b3 83 }
gsteiert 1:03aeb304d3b3 84 if (offDelay > 0) { offDelay -= 1; }
gsteiert 2:405cc6627ffb 85 else { dly = true; }
gsteiert 1:03aeb304d3b3 86 }
gsteiert 0:803011eae289 87 }