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
Revision 1:03aeb304d3b3, committed 2014-06-22
- Comitter:
- gsteiert
- Date:
- Sun Jun 22 23:04:51 2014 +0000
- Parent:
- 0:803011eae289
- Child:
- 2:405cc6627ffb
- Commit message:
- Includes support for dual row, but commented out.;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Apr 26 03:37:00 2014 +0000
+++ b/main.cpp Sun Jun 22 23:04:51 2014 +0000
@@ -2,14 +2,70 @@
#include "MAX14661.h"
MAX14661 mux(D14, D15);
-DigitalOut pinRTS(D13);
-DigitalIn pinRX(D0); // Set as input to remove load from mbedTX
-DigitalIn pinTX(D1); // Set as input to remove load from mbedRX
+I2C i2c(D14, D15);
+DigitalOut r(LED1);
+DigitalOut g(LED2);
+DigitalOut b(LED3);
+//DigitalIn pa3(D12); // Set as input to remove load from PA3
+//DigitalIn pa4(D13); // Set as input to remove load from PA4
+DigitalIn pb3(D6); // Set as input to remove load from PB3
+DigitalIn pb4(D7); // Set as input to remove load from PB4
+
+const int alsAddr = 0x94;
+const char alsLim = 0x01;
int main()
{
- pinRTS=0; // Not Ready to Send
- // D0 (mbedTX) + PA2 (TXD) D1 (mbedRX) + PA3 (RXD)
- mux.setAB((MAX14661::SW01 | MAX14661::SW13), (MAX14661::SW02 | MAX14661::SW12));
- pinRTS=1; // Ready to Send
+ char cmd[2];
+
+/* // SDA(D14) + PA4(D13) + PB4(D7) , SCL(D15) + PA3(D12) + PB3(D6)
+ mux.setAB((MAX14661::SW10 | MAX14661::SW11 | MAX14661::SW08),
+ (MAX14661::SW09 | MAX14661::SW12 | MAX14661::SW07));
+*/
+
+ // SDA (D14) + PB4 (D7) SCL (D15) + PB3 (D6)
+ mux.setAB((MAX14661::SW10 | MAX14661::SW08),
+ (MAX14661::SW09 | MAX14661::SW07));
+
+ cmd[0] = 0x02; // Receive Register
+ cmd[1] = 0xFF; // 1.56ms, 128x
+ i2c.write(alsAddr, cmd, 2);
+
+ cmd[0] = 0x03; // Transmit Register
+ cmd[1] = 0x0F; // 110mA
+ i2c.write(alsAddr, cmd, 2);
+
+ cmd[0] = 0x01; // Config Register
+ cmd[1] = 0x10; // ALS/Prox Mode
+ i2c.write(alsAddr, cmd, 2);
+
+ bool lastProx = false;
+ int offDelay = 0;
+ r = false;
+ g = false;
+ b = false;
+
+ while (true) {
+ wait (0.02);
+ cmd[0] = 0x04; // ALS Data Register
+ i2c.write(alsAddr, cmd, 1);
+ i2c.read(alsAddr, cmd, 1);
+ g = (cmd[0] < alsLim);
+
+ cmd[0] = 0x16; // Prox Data Register
+ i2c.write(alsAddr, cmd, 1);
+ i2c.read(alsAddr, cmd, 1);
+ if (cmd[0]) {
+ if (!lastProx) {
+ r = !r;
+ }
+ lastProx = true;
+ offDelay = 250;
+ b = false;
+ } else {
+ lastProx = false;
+ }
+ if (offDelay > 0) { offDelay -= 1; }
+ else { b = true; }
+ }
}
\ No newline at end of file
--- a/mbed.bld Sat Apr 26 03:37:00 2014 +0000 +++ b/mbed.bld Sun Jun 22 23:04:51 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721 \ No newline at end of file

Ambient Light and Proximity Sensor MAX44000