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@13:fb522023a522, 2016-10-19 (annotated)
- Committer:
- switches
- Date:
- Wed Oct 19 17:11:00 2016 +0000
- Revision:
- 13:fb522023a522
- Parent:
- 11:a799d1525a4d
Changed drive strength to 10mA (down from 110mA). This reduces the sensitivity and range of the proximity sensor, but it is compatible with MAX44000PMB1 boards that were built with 33 Ohm resistors inline with the power supply.
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. |
| switches | 11:a799d1525a4d | 3 | * |
| switches | 11:a799d1525a4d | 4 | * This is written to work with the ARD2PMD adapter board and |
| switches | 11:a799d1525a4d | 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. |
| switches | 11:a799d1525a4d | 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 |
| switches | 11:a799d1525a4d | 15 | * |
| switches | 11:a799d1525a4d | 16 | * Some boards use D13 for an LED signal, so this example uses the second |
| switches | 11:a799d1525a4d | 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 | 13:fb522023a522 | 37 | max44000.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_64X, MAX44000::ALSPGA_1X, MAX44000::DRV_10); |
| 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 | } |
| switches | 11:a799d1525a4d | 62 | if (offDelay > 0) { |
| switches | 11:a799d1525a4d | 63 | offDelay -= 1; |
| switches | 11:a799d1525a4d | 64 | } else { |
| switches | 11:a799d1525a4d | 65 | dly = true; |
| switches | 11:a799d1525a4d | 66 | } |
| gsteiert | 1:03aeb304d3b3 | 67 | } |
| gsteiert | 0:803011eae289 | 68 | } |

Ambient Light and Proximity Sensor MAX44000