
This demonstrates some of the capabilities of the MAX44000. It is written to work with the ARD2PMD adapter board and the MAX44000PMB1. It uses the standard Arduino pin names and will compile for most Arduino form-factor mbed boards.
This demonstrates some of the capabilities of the MAX44000.
This is written to work with the ARD2PMD adapter board and the MAX44000PMB1. It uses the standard Arduino pin names and it will compile for most Arduino form-factor mbed boards.
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.
- LED1 toggles when something is first detected by the proximity sensor.
- LED2 indicates when the Ambient Light Sensor reads grater than 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.
The following boards have been tested to work:
- MAX32600MBED
- FRDM-KL25Z
- FRDM-K64F
- Seeeduino Arch (LEDs inverted)
- Seeeduino Arch Pro
- ST Nucleo F401RE (only one LED, inverted)
main.cpp@5:2a360754fea6, 2016-04-08 (annotated)
- Committer:
- gsteiert
- Date:
- Fri Apr 08 22:37:02 2016 +0000
- Revision:
- 5:2a360754fea6
- Parent:
- 4:226ef11c3ef4
Updated mbed library. ; Replaced MAX14661 library with Ard2Pmod Library. ; Added MAX32600MBED to list of tested boards.
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: |
gsteiert | 5:2a360754fea6 | 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 |
gsteiert | 3:61cc32322303 | 19 | * ST Nucleo F401RE (only one LED, inverted) |
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" |
gsteiert | 5:2a360754fea6 | 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 |
gsteiert | 1:03aeb304d3b3 | 34 | |
gsteiert | 1:03aeb304d3b3 | 35 | const int alsAddr = 0x94; |
gsteiert | 4:226ef11c3ef4 | 36 | const int alsLim = 0x0008; |
gsteiert | 0:803011eae289 | 37 | |
gsteiert | 0:803011eae289 | 38 | int main() |
gsteiert | 0:803011eae289 | 39 | { |
gsteiert | 1:03aeb304d3b3 | 40 | char cmd[2]; |
gsteiert | 4:226ef11c3ef4 | 41 | int alsData; |
gsteiert | 1:03aeb304d3b3 | 42 | |
gsteiert | 5:2a360754fea6 | 43 | Ard2Pmod ard2pmd(Ard2Pmod::PMOD_TYPE_I2C_B); // Configure Ard2Pmod board for I2C on row B |
gsteiert | 1:03aeb304d3b3 | 44 | |
gsteiert | 1:03aeb304d3b3 | 45 | cmd[0] = 0x02; // Receive Register |
gsteiert | 4:226ef11c3ef4 | 46 | cmd[1] = 0xFC; // 1.56ms, 1x |
gsteiert | 1:03aeb304d3b3 | 47 | i2c.write(alsAddr, cmd, 2); |
gsteiert | 1:03aeb304d3b3 | 48 | |
gsteiert | 1:03aeb304d3b3 | 49 | cmd[0] = 0x03; // Transmit Register |
gsteiert | 1:03aeb304d3b3 | 50 | cmd[1] = 0x0F; // 110mA |
gsteiert | 1:03aeb304d3b3 | 51 | i2c.write(alsAddr, cmd, 2); |
gsteiert | 1:03aeb304d3b3 | 52 | |
gsteiert | 1:03aeb304d3b3 | 53 | cmd[0] = 0x01; // Config Register |
gsteiert | 1:03aeb304d3b3 | 54 | cmd[1] = 0x10; // ALS/Prox Mode |
gsteiert | 1:03aeb304d3b3 | 55 | i2c.write(alsAddr, cmd, 2); |
gsteiert | 1:03aeb304d3b3 | 56 | |
gsteiert | 1:03aeb304d3b3 | 57 | bool lastProx = false; |
gsteiert | 1:03aeb304d3b3 | 58 | int offDelay = 0; |
gsteiert | 2:405cc6627ffb | 59 | tog = false; |
gsteiert | 2:405cc6627ffb | 60 | als = false; |
gsteiert | 2:405cc6627ffb | 61 | dly = false; |
gsteiert | 1:03aeb304d3b3 | 62 | |
gsteiert | 1:03aeb304d3b3 | 63 | while (true) { |
gsteiert | 1:03aeb304d3b3 | 64 | wait (0.02); |
gsteiert | 4:226ef11c3ef4 | 65 | cmd[0] = 0x05; // ALS Data Register Low |
gsteiert | 4:226ef11c3ef4 | 66 | i2c.write(alsAddr, cmd, 1, true); |
gsteiert | 1:03aeb304d3b3 | 67 | i2c.read(alsAddr, cmd, 1); |
gsteiert | 4:226ef11c3ef4 | 68 | alsData = cmd[0]; |
gsteiert | 4:226ef11c3ef4 | 69 | als = (alsData < alsLim); |
gsteiert | 1:03aeb304d3b3 | 70 | |
gsteiert | 1:03aeb304d3b3 | 71 | cmd[0] = 0x16; // Prox Data Register |
gsteiert | 4:226ef11c3ef4 | 72 | i2c.write(alsAddr, cmd, 1, true); |
gsteiert | 1:03aeb304d3b3 | 73 | i2c.read(alsAddr, cmd, 1); |
gsteiert | 1:03aeb304d3b3 | 74 | if (cmd[0]) { |
gsteiert | 1:03aeb304d3b3 | 75 | if (!lastProx) { |
gsteiert | 2:405cc6627ffb | 76 | tog = !tog; |
gsteiert | 1:03aeb304d3b3 | 77 | } |
gsteiert | 1:03aeb304d3b3 | 78 | lastProx = true; |
gsteiert | 1:03aeb304d3b3 | 79 | offDelay = 250; |
gsteiert | 2:405cc6627ffb | 80 | dly = false; |
gsteiert | 1:03aeb304d3b3 | 81 | } else { |
gsteiert | 1:03aeb304d3b3 | 82 | lastProx = false; |
gsteiert | 1:03aeb304d3b3 | 83 | } |
gsteiert | 1:03aeb304d3b3 | 84 | if (offDelay > 0) { offDelay -= 1; } |
gsteiert | 2:405cc6627ffb | 85 | else { dly = true; } |
gsteiert | 1:03aeb304d3b3 | 86 | } |
gsteiert | 0:803011eae289 | 87 | } |