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:21:11 2016 +0000
Revision:
8:fb192510004d
Parent:
7:0a59d9e914f3
Child:
9:22f6995ab785
Added MAX32600MBED to list of tested boards

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:
switches 8:fb192510004d 14 * MAX32600MBED
gsteiert 3:61cc32322303 15 * FRDM-KL25Z
gsteiert 3:61cc32322303 16 * FRDM-K64F
gsteiert 3:61cc32322303 17 * Seeeduino Arch (LEDs inverted)
gsteiert 3:61cc32322303 18 * Seeeduino Arch Pro
switches 5:b39bfe8e3d09 19 * ST Nucleo L152RE/F401RE (B row only, single LED, inverted)
switches 5:b39bfe8e3d09 20 * LPCXpresso1549
gsteiert 2:405cc6627ffb 21 *
gsteiert 2:405cc6627ffb 22 * Some boards use D13 for an LED signal, so this example uses the second
gsteiert 2:405cc6627ffb 23 * row (row B, pins 7 through 12) of the Pmod connector.
gsteiert 2:405cc6627ffb 24 */
gsteiert 2:405cc6627ffb 25
gsteiert 0:803011eae289 26 #include "mbed.h"
switches 5:b39bfe8e3d09 27 #include "ard2pmod.h"
gsteiert 0:803011eae289 28
gsteiert 1:03aeb304d3b3 29 I2C i2c(D14, D15);
gsteiert 2:405cc6627ffb 30 DigitalOut tog(LED1);
gsteiert 2:405cc6627ffb 31 DigitalOut als(LED2);
gsteiert 2:405cc6627ffb 32 DigitalOut dly(LED3);
gsteiert 1:03aeb304d3b3 33 DigitalIn pb3(D6); // Set as input to remove load from PB3
gsteiert 1:03aeb304d3b3 34 DigitalIn pb4(D7); // Set as input to remove load from PB4
switches 5:b39bfe8e3d09 35 DigitalIn pa3(D12); // Set as input to remove load from PA3
switches 5:b39bfe8e3d09 36 DigitalIn pa4(D13); // Set as input to remove load from PA4
gsteiert 1:03aeb304d3b3 37
gsteiert 1:03aeb304d3b3 38 const int alsAddr = 0x94;
gsteiert 4:226ef11c3ef4 39 const int alsLim = 0x0008;
gsteiert 0:803011eae289 40
gsteiert 0:803011eae289 41 int main()
gsteiert 0:803011eae289 42 {
switches 7:0a59d9e914f3 43 Ard2Pmod ard2pmod(Ard2Pmod::PMOD_TYPE_I2C_B); // Configure ard2pmod multiplexer for I2C
gsteiert 1:03aeb304d3b3 44 char cmd[2];
gsteiert 4:226ef11c3ef4 45 int alsData;
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 }