Demonstrates the MAX44000 library and some of the features of the MAX44000

Dependencies:   MAX44000 ard2pmod mbed

Fork of ALS_ARD2PMOD_Demo by Maxim Integrated

MAX44000PMB1 Demonstration

This demonstrates some of the capabilities of the MAX44000. This is written to work with the MAXREFDES72# adapter board and the MAX44000PMB1 peripheral module. It uses the standard Arduino pin names and it will compile for most arduino form-factor mbed boards. /media/uploads/switches/max44000pmb1_demo.jpg To run this demonstration you will need:

In this demonstration the LEDs are changed based on data from the sensor.

  • LED1 toggles when something is first detected by the proximity sensor.
  • LED2 indicates when the Ambient Light Sensor reads greater than a set value (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.

Note: 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. /media/uploads/switches/max44000_align.jpg

Tested platform boards

Links to external supporting material

Committer:
switches
Date:
Fri Apr 08 22:18:06 2016 +0000
Revision:
7:0a59d9e914f3
Parent:
5:b39bfe8e3d09
Child:
8:fb192510004d
Added namespace to PMOD_TYPE

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
switches 5:b39bfe8e3d09 18 * ST Nucleo L152RE/F401RE (B row only, single LED, inverted)
switches 5:b39bfe8e3d09 19 * LPCXpresso1549
gsteiert 2:405cc6627ffb 20 *
gsteiert 2:405cc6627ffb 21 * Some boards use D13 for an LED signal, so this example uses the second
gsteiert 2:405cc6627ffb 22 * row (row B, pins 7 through 12) of the Pmod connector.
gsteiert 2:405cc6627ffb 23 */
gsteiert 2:405cc6627ffb 24
gsteiert 0:803011eae289 25 #include "mbed.h"
switches 5:b39bfe8e3d09 26 #include "ard2pmod.h"
gsteiert 0:803011eae289 27
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
switches 5:b39bfe8e3d09 34 DigitalIn pa3(D12); // Set as input to remove load from PA3
switches 5:b39bfe8e3d09 35 DigitalIn pa4(D13); // Set as input to remove load from PA4
gsteiert 1:03aeb304d3b3 36
gsteiert 1:03aeb304d3b3 37 const int alsAddr = 0x94;
gsteiert 4:226ef11c3ef4 38 const int alsLim = 0x0008;
gsteiert 0:803011eae289 39
gsteiert 0:803011eae289 40 int main()
gsteiert 0:803011eae289 41 {
switches 7:0a59d9e914f3 42 Ard2Pmod ard2pmod(Ard2Pmod::PMOD_TYPE_I2C_B); // Configure ard2pmod multiplexer for I2C
gsteiert 1:03aeb304d3b3 43 char cmd[2];
gsteiert 4:226ef11c3ef4 44 int alsData;
gsteiert 1:03aeb304d3b3 45
gsteiert 1:03aeb304d3b3 46 cmd[0] = 0x02; // Receive Register
gsteiert 4:226ef11c3ef4 47 cmd[1] = 0xFC; // 1.56ms, 1x
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 4:226ef11c3ef4 66 cmd[0] = 0x05; // ALS Data Register Low
gsteiert 4:226ef11c3ef4 67 i2c.write(alsAddr, cmd, 1, true);
gsteiert 1:03aeb304d3b3 68 i2c.read(alsAddr, cmd, 1);
gsteiert 4:226ef11c3ef4 69 alsData = cmd[0];
gsteiert 4:226ef11c3ef4 70 als = (alsData < alsLim);
gsteiert 1:03aeb304d3b3 71
gsteiert 1:03aeb304d3b3 72 cmd[0] = 0x16; // Prox Data Register
gsteiert 4:226ef11c3ef4 73 i2c.write(alsAddr, cmd, 1, true);
gsteiert 1:03aeb304d3b3 74 i2c.read(alsAddr, cmd, 1);
gsteiert 1:03aeb304d3b3 75 if (cmd[0]) {
gsteiert 1:03aeb304d3b3 76 if (!lastProx) {
gsteiert 2:405cc6627ffb 77 tog = !tog;
gsteiert 1:03aeb304d3b3 78 }
gsteiert 1:03aeb304d3b3 79 lastProx = true;
gsteiert 1:03aeb304d3b3 80 offDelay = 250;
gsteiert 2:405cc6627ffb 81 dly = false;
gsteiert 1:03aeb304d3b3 82 } else {
gsteiert 1:03aeb304d3b3 83 lastProx = false;
gsteiert 1:03aeb304d3b3 84 }
gsteiert 1:03aeb304d3b3 85 if (offDelay > 0) { offDelay -= 1; }
gsteiert 2:405cc6627ffb 86 else { dly = true; }
gsteiert 1:03aeb304d3b3 87 }
gsteiert 0:803011eae289 88 }