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@1:03aeb304d3b3, 2014-06-22 (annotated)
- Committer:
- gsteiert
- Date:
- Sun Jun 22 23:04:51 2014 +0000
- Revision:
- 1:03aeb304d3b3
- Parent:
- 0:803011eae289
- Child:
- 2:405cc6627ffb
Includes support for dual row, but commented out.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gsteiert | 0:803011eae289 | 1 | #include "mbed.h" |
gsteiert | 0:803011eae289 | 2 | #include "MAX14661.h" |
gsteiert | 0:803011eae289 | 3 | |
gsteiert | 0:803011eae289 | 4 | MAX14661 mux(D14, D15); |
gsteiert | 1:03aeb304d3b3 | 5 | I2C i2c(D14, D15); |
gsteiert | 1:03aeb304d3b3 | 6 | DigitalOut r(LED1); |
gsteiert | 1:03aeb304d3b3 | 7 | DigitalOut g(LED2); |
gsteiert | 1:03aeb304d3b3 | 8 | DigitalOut b(LED3); |
gsteiert | 1:03aeb304d3b3 | 9 | //DigitalIn pa3(D12); // Set as input to remove load from PA3 |
gsteiert | 1:03aeb304d3b3 | 10 | //DigitalIn pa4(D13); // Set as input to remove load from PA4 |
gsteiert | 1:03aeb304d3b3 | 11 | DigitalIn pb3(D6); // Set as input to remove load from PB3 |
gsteiert | 1:03aeb304d3b3 | 12 | DigitalIn pb4(D7); // Set as input to remove load from PB4 |
gsteiert | 1:03aeb304d3b3 | 13 | |
gsteiert | 1:03aeb304d3b3 | 14 | const int alsAddr = 0x94; |
gsteiert | 1:03aeb304d3b3 | 15 | const char alsLim = 0x01; |
gsteiert | 0:803011eae289 | 16 | |
gsteiert | 0:803011eae289 | 17 | int main() |
gsteiert | 0:803011eae289 | 18 | { |
gsteiert | 1:03aeb304d3b3 | 19 | char cmd[2]; |
gsteiert | 1:03aeb304d3b3 | 20 | |
gsteiert | 1:03aeb304d3b3 | 21 | /* // SDA(D14) + PA4(D13) + PB4(D7) , SCL(D15) + PA3(D12) + PB3(D6) |
gsteiert | 1:03aeb304d3b3 | 22 | mux.setAB((MAX14661::SW10 | MAX14661::SW11 | MAX14661::SW08), |
gsteiert | 1:03aeb304d3b3 | 23 | (MAX14661::SW09 | MAX14661::SW12 | MAX14661::SW07)); |
gsteiert | 1:03aeb304d3b3 | 24 | */ |
gsteiert | 1:03aeb304d3b3 | 25 | |
gsteiert | 1:03aeb304d3b3 | 26 | // SDA (D14) + PB4 (D7) SCL (D15) + PB3 (D6) |
gsteiert | 1:03aeb304d3b3 | 27 | mux.setAB((MAX14661::SW10 | MAX14661::SW08), |
gsteiert | 1:03aeb304d3b3 | 28 | (MAX14661::SW09 | MAX14661::SW07)); |
gsteiert | 1:03aeb304d3b3 | 29 | |
gsteiert | 1:03aeb304d3b3 | 30 | cmd[0] = 0x02; // Receive Register |
gsteiert | 1:03aeb304d3b3 | 31 | cmd[1] = 0xFF; // 1.56ms, 128x |
gsteiert | 1:03aeb304d3b3 | 32 | i2c.write(alsAddr, cmd, 2); |
gsteiert | 1:03aeb304d3b3 | 33 | |
gsteiert | 1:03aeb304d3b3 | 34 | cmd[0] = 0x03; // Transmit Register |
gsteiert | 1:03aeb304d3b3 | 35 | cmd[1] = 0x0F; // 110mA |
gsteiert | 1:03aeb304d3b3 | 36 | i2c.write(alsAddr, cmd, 2); |
gsteiert | 1:03aeb304d3b3 | 37 | |
gsteiert | 1:03aeb304d3b3 | 38 | cmd[0] = 0x01; // Config Register |
gsteiert | 1:03aeb304d3b3 | 39 | cmd[1] = 0x10; // ALS/Prox Mode |
gsteiert | 1:03aeb304d3b3 | 40 | i2c.write(alsAddr, cmd, 2); |
gsteiert | 1:03aeb304d3b3 | 41 | |
gsteiert | 1:03aeb304d3b3 | 42 | bool lastProx = false; |
gsteiert | 1:03aeb304d3b3 | 43 | int offDelay = 0; |
gsteiert | 1:03aeb304d3b3 | 44 | r = false; |
gsteiert | 1:03aeb304d3b3 | 45 | g = false; |
gsteiert | 1:03aeb304d3b3 | 46 | b = false; |
gsteiert | 1:03aeb304d3b3 | 47 | |
gsteiert | 1:03aeb304d3b3 | 48 | while (true) { |
gsteiert | 1:03aeb304d3b3 | 49 | wait (0.02); |
gsteiert | 1:03aeb304d3b3 | 50 | cmd[0] = 0x04; // ALS Data Register |
gsteiert | 1:03aeb304d3b3 | 51 | i2c.write(alsAddr, cmd, 1); |
gsteiert | 1:03aeb304d3b3 | 52 | i2c.read(alsAddr, cmd, 1); |
gsteiert | 1:03aeb304d3b3 | 53 | g = (cmd[0] < alsLim); |
gsteiert | 1:03aeb304d3b3 | 54 | |
gsteiert | 1:03aeb304d3b3 | 55 | cmd[0] = 0x16; // Prox Data Register |
gsteiert | 1:03aeb304d3b3 | 56 | i2c.write(alsAddr, cmd, 1); |
gsteiert | 1:03aeb304d3b3 | 57 | i2c.read(alsAddr, cmd, 1); |
gsteiert | 1:03aeb304d3b3 | 58 | if (cmd[0]) { |
gsteiert | 1:03aeb304d3b3 | 59 | if (!lastProx) { |
gsteiert | 1:03aeb304d3b3 | 60 | r = !r; |
gsteiert | 1:03aeb304d3b3 | 61 | } |
gsteiert | 1:03aeb304d3b3 | 62 | lastProx = true; |
gsteiert | 1:03aeb304d3b3 | 63 | offDelay = 250; |
gsteiert | 1:03aeb304d3b3 | 64 | b = false; |
gsteiert | 1:03aeb304d3b3 | 65 | } else { |
gsteiert | 1:03aeb304d3b3 | 66 | lastProx = false; |
gsteiert | 1:03aeb304d3b3 | 67 | } |
gsteiert | 1:03aeb304d3b3 | 68 | if (offDelay > 0) { offDelay -= 1; } |
gsteiert | 1:03aeb304d3b3 | 69 | else { b = true; } |
gsteiert | 1:03aeb304d3b3 | 70 | } |
gsteiert | 0:803011eae289 | 71 | } |