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:
Wed May 04 16:40:23 2016 +0000
Revision:
10:102944c2d59c
Parent:
9:22f6995ab785
Child:
11:a799d1525a4d
Removed input definitions on D12 and D13

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 2:405cc6627ffb 15 *
gsteiert 2:405cc6627ffb 16 * Some boards use D13 for an LED signal, so this example uses the second
gsteiert 2:405cc6627ffb 17 * row (row B, pins 7 through 12) of the Pmod connector.
gsteiert 2:405cc6627ffb 18 */
gsteiert 2:405cc6627ffb 19
gsteiert 0:803011eae289 20 #include "mbed.h"
switches 5:b39bfe8e3d09 21 #include "ard2pmod.h"
switches 9:22f6995ab785 22 #include "MAX44000.h"
gsteiert 0:803011eae289 23
switches 9:22f6995ab785 24 MAX44000 max44000(D14, D15);
gsteiert 2:405cc6627ffb 25 DigitalOut tog(LED1);
gsteiert 2:405cc6627ffb 26 DigitalOut als(LED2);
gsteiert 2:405cc6627ffb 27 DigitalOut dly(LED3);
gsteiert 1:03aeb304d3b3 28 DigitalIn pb3(D6); // Set as input to remove load from PB3
gsteiert 1:03aeb304d3b3 29 DigitalIn pb4(D7); // Set as input to remove load from PB4
gsteiert 1:03aeb304d3b3 30
gsteiert 4:226ef11c3ef4 31 const int alsLim = 0x0008;
gsteiert 0:803011eae289 32
gsteiert 0:803011eae289 33 int main()
gsteiert 0:803011eae289 34 {
switches 9:22f6995ab785 35 Ard2Pmod ard2pmod(Ard2Pmod::PMOD_TYPE_I2C_B); // Configure ard2pmod multiplexer for I2C row B (bottom row)
gsteiert 1:03aeb304d3b3 36
switches 9:22f6995ab785 37 max44000.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_64X, MAX44000::ALSPGA_1X, MAX44000::DRV_110);
gsteiert 1:03aeb304d3b3 38
gsteiert 1:03aeb304d3b3 39 bool lastProx = false;
gsteiert 1:03aeb304d3b3 40 int offDelay = 0;
gsteiert 2:405cc6627ffb 41 tog = false;
gsteiert 2:405cc6627ffb 42 als = false;
gsteiert 2:405cc6627ffb 43 dly = false;
gsteiert 1:03aeb304d3b3 44
gsteiert 1:03aeb304d3b3 45 while (true) {
gsteiert 1:03aeb304d3b3 46 wait (0.02);
switches 9:22f6995ab785 47 int alsData = max44000.readALS();
switches 9:22f6995ab785 48 int proxData = max44000.readReg(MAX44000::REG_PRX_DATA);
switches 9:22f6995ab785 49
gsteiert 4:226ef11c3ef4 50 als = (alsData < alsLim);
gsteiert 1:03aeb304d3b3 51
switches 9:22f6995ab785 52 if (proxData) {
gsteiert 1:03aeb304d3b3 53 if (!lastProx) {
gsteiert 2:405cc6627ffb 54 tog = !tog;
gsteiert 1:03aeb304d3b3 55 }
gsteiert 1:03aeb304d3b3 56 lastProx = true;
gsteiert 1:03aeb304d3b3 57 offDelay = 250;
gsteiert 2:405cc6627ffb 58 dly = false;
gsteiert 1:03aeb304d3b3 59 } else {
gsteiert 1:03aeb304d3b3 60 lastProx = false;
gsteiert 1:03aeb304d3b3 61 }
gsteiert 1:03aeb304d3b3 62 if (offDelay > 0) { offDelay -= 1; }
gsteiert 2:405cc6627ffb 63 else { dly = true; }
gsteiert 1:03aeb304d3b3 64 }
gsteiert 0:803011eae289 65 }