Demonstrates the MAX44000 library and some of the features of the MAX44000
Dependencies: MAX44000 ard2pmod mbed
Fork of ALS_ARD2PMOD_Demo by
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. To run this demonstration you will need:
- MAX44000PMB1 Ambient Light / Proximity Sensor Peripheral Module
- MAXREFDES72# Pmod Adapter for Arduino Platforms
- An mbed enabled board with an Arduino compatible socket. We recommend the MAX32600MBED
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.
Tested platform boards
Links to external supporting material
- MAX44000PMB1 Ambient Light / Proximity Sensor Peripheral Module
- MAXREFDES72# Pmod Adapter for Arduino Platforms
- MAX32600MBED
main.cpp@9:22f6995ab785, 2016-05-04 (annotated)
- Committer:
- switches
- Date:
- Wed May 04 16:39:08 2016 +0000
- Revision:
- 9:22f6995ab785
- Parent:
- 8:fb192510004d
- Child:
- 10:102944c2d59c
MAX44000 Demo. draft for release
Who changed what in which revision?
User | Revision | Line number | New 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 |
switches | 5:b39bfe8e3d09 | 30 | DigitalIn pa3(D12); // Set as input to remove load from PA3 |
switches | 5:b39bfe8e3d09 | 31 | DigitalIn pa4(D13); // Set as input to remove load from PA4 |
gsteiert | 1:03aeb304d3b3 | 32 | |
gsteiert | 4:226ef11c3ef4 | 33 | const int alsLim = 0x0008; |
gsteiert | 0:803011eae289 | 34 | |
gsteiert | 0:803011eae289 | 35 | int main() |
gsteiert | 0:803011eae289 | 36 | { |
switches | 9:22f6995ab785 | 37 | Ard2Pmod ard2pmod(Ard2Pmod::PMOD_TYPE_I2C_B); // Configure ard2pmod multiplexer for I2C row B (bottom row) |
gsteiert | 1:03aeb304d3b3 | 38 | |
switches | 9:22f6995ab785 | 39 | max44000.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_64X, MAX44000::ALSPGA_1X, MAX44000::DRV_110); |
gsteiert | 1:03aeb304d3b3 | 40 | |
gsteiert | 1:03aeb304d3b3 | 41 | bool lastProx = false; |
gsteiert | 1:03aeb304d3b3 | 42 | int offDelay = 0; |
gsteiert | 2:405cc6627ffb | 43 | tog = false; |
gsteiert | 2:405cc6627ffb | 44 | als = false; |
gsteiert | 2:405cc6627ffb | 45 | dly = false; |
gsteiert | 1:03aeb304d3b3 | 46 | |
gsteiert | 1:03aeb304d3b3 | 47 | while (true) { |
gsteiert | 1:03aeb304d3b3 | 48 | wait (0.02); |
switches | 9:22f6995ab785 | 49 | int alsData = max44000.readALS(); |
switches | 9:22f6995ab785 | 50 | int proxData = max44000.readReg(MAX44000::REG_PRX_DATA); |
switches | 9:22f6995ab785 | 51 | |
gsteiert | 4:226ef11c3ef4 | 52 | als = (alsData < alsLim); |
gsteiert | 1:03aeb304d3b3 | 53 | |
switches | 9:22f6995ab785 | 54 | if (proxData) { |
gsteiert | 1:03aeb304d3b3 | 55 | if (!lastProx) { |
gsteiert | 2:405cc6627ffb | 56 | tog = !tog; |
gsteiert | 1:03aeb304d3b3 | 57 | } |
gsteiert | 1:03aeb304d3b3 | 58 | lastProx = true; |
gsteiert | 1:03aeb304d3b3 | 59 | offDelay = 250; |
gsteiert | 2:405cc6627ffb | 60 | dly = false; |
gsteiert | 1:03aeb304d3b3 | 61 | } else { |
gsteiert | 1:03aeb304d3b3 | 62 | lastProx = false; |
gsteiert | 1:03aeb304d3b3 | 63 | } |
gsteiert | 1:03aeb304d3b3 | 64 | if (offDelay > 0) { offDelay -= 1; } |
gsteiert | 2:405cc6627ffb | 65 | else { dly = true; } |
gsteiert | 1:03aeb304d3b3 | 66 | } |
gsteiert | 0:803011eae289 | 67 | } |