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 30 22:32:02 2014 +0000
Revision:
4:226ef11c3ef4
Parent:
3:61cc32322303
Child:
5:2a360754fea6
Fixed ALS data reading

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 4:226ef11c3ef4 36 const int alsLim = 0x0008;
gsteiert 0:803011eae289 37
gsteiert 0:803011eae289 38 int main()
gsteiert 0:803011eae289 39 {
gsteiert 1:03aeb304d3b3 40 char cmd[2];
gsteiert 4:226ef11c3ef4 41 int alsData;
gsteiert 1:03aeb304d3b3 42
gsteiert 2:405cc6627ffb 43 // SDA (D14) + PB4 (D7) SCL (D15) + PB3 (D6)
gsteiert 1:03aeb304d3b3 44 mux.setAB((MAX14661::SW10 | MAX14661::SW08),
gsteiert 1:03aeb304d3b3 45 (MAX14661::SW09 | MAX14661::SW07));
gsteiert 1:03aeb304d3b3 46
gsteiert 1:03aeb304d3b3 47 cmd[0] = 0x02; // Receive Register
gsteiert 4:226ef11c3ef4 48 cmd[1] = 0xFC; // 1.56ms, 1x
gsteiert 1:03aeb304d3b3 49 i2c.write(alsAddr, cmd, 2);
gsteiert 1:03aeb304d3b3 50
gsteiert 1:03aeb304d3b3 51 cmd[0] = 0x03; // Transmit Register
gsteiert 1:03aeb304d3b3 52 cmd[1] = 0x0F; // 110mA
gsteiert 1:03aeb304d3b3 53 i2c.write(alsAddr, cmd, 2);
gsteiert 1:03aeb304d3b3 54
gsteiert 1:03aeb304d3b3 55 cmd[0] = 0x01; // Config Register
gsteiert 1:03aeb304d3b3 56 cmd[1] = 0x10; // ALS/Prox Mode
gsteiert 1:03aeb304d3b3 57 i2c.write(alsAddr, cmd, 2);
gsteiert 1:03aeb304d3b3 58
gsteiert 1:03aeb304d3b3 59 bool lastProx = false;
gsteiert 1:03aeb304d3b3 60 int offDelay = 0;
gsteiert 2:405cc6627ffb 61 tog = false;
gsteiert 2:405cc6627ffb 62 als = false;
gsteiert 2:405cc6627ffb 63 dly = false;
gsteiert 1:03aeb304d3b3 64
gsteiert 1:03aeb304d3b3 65 while (true) {
gsteiert 1:03aeb304d3b3 66 wait (0.02);
gsteiert 4:226ef11c3ef4 67 cmd[0] = 0x05; // ALS Data Register Low
gsteiert 4:226ef11c3ef4 68 i2c.write(alsAddr, cmd, 1, true);
gsteiert 1:03aeb304d3b3 69 i2c.read(alsAddr, cmd, 1);
gsteiert 4:226ef11c3ef4 70 alsData = cmd[0];
gsteiert 4:226ef11c3ef4 71 als = (alsData < alsLim);
gsteiert 1:03aeb304d3b3 72
gsteiert 1:03aeb304d3b3 73 cmd[0] = 0x16; // Prox Data Register
gsteiert 4:226ef11c3ef4 74 i2c.write(alsAddr, cmd, 1, true);
gsteiert 1:03aeb304d3b3 75 i2c.read(alsAddr, cmd, 1);
gsteiert 1:03aeb304d3b3 76 if (cmd[0]) {
gsteiert 1:03aeb304d3b3 77 if (!lastProx) {
gsteiert 2:405cc6627ffb 78 tog = !tog;
gsteiert 1:03aeb304d3b3 79 }
gsteiert 1:03aeb304d3b3 80 lastProx = true;
gsteiert 1:03aeb304d3b3 81 offDelay = 250;
gsteiert 2:405cc6627ffb 82 dly = false;
gsteiert 1:03aeb304d3b3 83 } else {
gsteiert 1:03aeb304d3b3 84 lastProx = false;
gsteiert 1:03aeb304d3b3 85 }
gsteiert 1:03aeb304d3b3 86 if (offDelay > 0) { offDelay -= 1; }
gsteiert 2:405cc6627ffb 87 else { dly = true; }
gsteiert 1:03aeb304d3b3 88 }
gsteiert 0:803011eae289 89 }