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:03:54 2014 +0000
Revision:
2:405cc6627ffb
Parent:
1:03aeb304d3b3
Child:
3:61cc32322303
Publishing ALS Proximity Demo

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 2:405cc6627ffb 14 * FRDM-KL25Z, FRDM-K64F
gsteiert 2:405cc6627ffb 15 * Seeeduino Arch and Arch Pro (LEDs inverted)
gsteiert 2:405cc6627ffb 16 * ST Nucleo F401RE (only one LED)
gsteiert 2:405cc6627ffb 17 *
gsteiert 2:405cc6627ffb 18 * Some boards use D13 for an LED signal, so this example uses the second
gsteiert 2:405cc6627ffb 19 * row (row B, pins 7 through 12) of the Pmod connector.
gsteiert 2:405cc6627ffb 20 */
gsteiert 2:405cc6627ffb 21
gsteiert 0:803011eae289 22 #include "mbed.h"
gsteiert 0:803011eae289 23 #include "MAX14661.h"
gsteiert 0:803011eae289 24
gsteiert 0:803011eae289 25 MAX14661 mux(D14, D15);
gsteiert 1:03aeb304d3b3 26 I2C i2c(D14, D15);
gsteiert 2:405cc6627ffb 27 DigitalOut tog(LED1);
gsteiert 2:405cc6627ffb 28 DigitalOut als(LED2);
gsteiert 2:405cc6627ffb 29 DigitalOut dly(LED3);
gsteiert 1:03aeb304d3b3 30 DigitalIn pb3(D6); // Set as input to remove load from PB3
gsteiert 1:03aeb304d3b3 31 DigitalIn pb4(D7); // Set as input to remove load from PB4
gsteiert 1:03aeb304d3b3 32
gsteiert 1:03aeb304d3b3 33 const int alsAddr = 0x94;
gsteiert 1:03aeb304d3b3 34 const char alsLim = 0x01;
gsteiert 0:803011eae289 35
gsteiert 0:803011eae289 36 int main()
gsteiert 0:803011eae289 37 {
gsteiert 1:03aeb304d3b3 38 char cmd[2];
gsteiert 1:03aeb304d3b3 39
gsteiert 2:405cc6627ffb 40 // SDA (D14) + PB4 (D7) SCL (D15) + PB3 (D6)
gsteiert 1:03aeb304d3b3 41 mux.setAB((MAX14661::SW10 | MAX14661::SW08),
gsteiert 1:03aeb304d3b3 42 (MAX14661::SW09 | MAX14661::SW07));
gsteiert 1:03aeb304d3b3 43
gsteiert 1:03aeb304d3b3 44 cmd[0] = 0x02; // Receive Register
gsteiert 1:03aeb304d3b3 45 cmd[1] = 0xFF; // 1.56ms, 128x
gsteiert 1:03aeb304d3b3 46 i2c.write(alsAddr, cmd, 2);
gsteiert 1:03aeb304d3b3 47
gsteiert 1:03aeb304d3b3 48 cmd[0] = 0x03; // Transmit Register
gsteiert 1:03aeb304d3b3 49 cmd[1] = 0x0F; // 110mA
gsteiert 1:03aeb304d3b3 50 i2c.write(alsAddr, cmd, 2);
gsteiert 1:03aeb304d3b3 51
gsteiert 1:03aeb304d3b3 52 cmd[0] = 0x01; // Config Register
gsteiert 1:03aeb304d3b3 53 cmd[1] = 0x10; // ALS/Prox Mode
gsteiert 1:03aeb304d3b3 54 i2c.write(alsAddr, cmd, 2);
gsteiert 1:03aeb304d3b3 55
gsteiert 1:03aeb304d3b3 56 bool lastProx = false;
gsteiert 1:03aeb304d3b3 57 int offDelay = 0;
gsteiert 2:405cc6627ffb 58 tog = false;
gsteiert 2:405cc6627ffb 59 als = false;
gsteiert 2:405cc6627ffb 60 dly = false;
gsteiert 1:03aeb304d3b3 61
gsteiert 1:03aeb304d3b3 62 while (true) {
gsteiert 1:03aeb304d3b3 63 wait (0.02);
gsteiert 1:03aeb304d3b3 64 cmd[0] = 0x04; // ALS Data Register
gsteiert 1:03aeb304d3b3 65 i2c.write(alsAddr, cmd, 1);
gsteiert 1:03aeb304d3b3 66 i2c.read(alsAddr, cmd, 1);
gsteiert 2:405cc6627ffb 67 als = (cmd[0] < alsLim);
gsteiert 1:03aeb304d3b3 68
gsteiert 1:03aeb304d3b3 69 cmd[0] = 0x16; // Prox Data Register
gsteiert 1:03aeb304d3b3 70 i2c.write(alsAddr, cmd, 1);
gsteiert 1:03aeb304d3b3 71 i2c.read(alsAddr, cmd, 1);
gsteiert 1:03aeb304d3b3 72 if (cmd[0]) {
gsteiert 1:03aeb304d3b3 73 if (!lastProx) {
gsteiert 2:405cc6627ffb 74 tog = !tog;
gsteiert 1:03aeb304d3b3 75 }
gsteiert 1:03aeb304d3b3 76 lastProx = true;
gsteiert 1:03aeb304d3b3 77 offDelay = 250;
gsteiert 2:405cc6627ffb 78 dly = false;
gsteiert 1:03aeb304d3b3 79 } else {
gsteiert 1:03aeb304d3b3 80 lastProx = false;
gsteiert 1:03aeb304d3b3 81 }
gsteiert 1:03aeb304d3b3 82 if (offDelay > 0) { offDelay -= 1; }
gsteiert 2:405cc6627ffb 83 else { dly = true; }
gsteiert 1:03aeb304d3b3 84 }
gsteiert 0:803011eae289 85 }