Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX44000 ard2pmod mbed
Fork of ALS_ARD2PMOD_Demo by
main.cpp
00001 /* MAX44000 Ambient Light Sensor / Proximity Sensor Demo 00002 * This demonstrates some of the capabilities of the MAX44000. 00003 * 00004 * This is written to work with the ARD2PMD adapter board and 00005 * the MAX44000PMB1. It uses the standard Arduino pin names 00006 * and it will compile for most arduino form-factor mbed boards. 00007 * 00008 * LED1 toggles when something is first detected by the proximity sensor. 00009 * LED2 indicates when the Ambient Light Sensor reads grater than alsLim. 00010 * LED3 will stay on whenever something is detected by the proximity sensor 00011 * and stay on for an additional 5s after it is no longer detected. 00012 * 00013 * The following boards have been tested to work: 00014 * MAX32600MBED 00015 * 00016 * Some boards use D13 for an LED signal, so this example uses the second 00017 * row (row B, pins 7 through 12) of the Pmod connector. 00018 */ 00019 00020 #include "mbed.h" 00021 #include "ard2pmod.h" 00022 #include "MAX44000.h" 00023 00024 MAX44000 max44000(D14, D15); 00025 DigitalOut tog(LED1); 00026 DigitalOut als(LED2); 00027 DigitalOut dly(LED3); 00028 DigitalIn pb3(D6); // Set as input to remove load from PB3 00029 DigitalIn pb4(D7); // Set as input to remove load from PB4 00030 00031 const int alsLim = 0x0008; 00032 00033 int main() 00034 { 00035 Ard2Pmod ard2pmod(Ard2Pmod::PMOD_TYPE_I2C_B); // Configure ard2pmod multiplexer for I2C row B (bottom row) 00036 00037 max44000.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_64X, MAX44000::ALSPGA_1X, MAX44000::DRV_10); 00038 00039 bool lastProx = false; 00040 int offDelay = 0; 00041 tog = false; 00042 als = false; 00043 dly = false; 00044 00045 while (true) { 00046 wait (0.02); 00047 int alsData = max44000.readALS(); 00048 int proxData = max44000.readReg(MAX44000::REG_PRX_DATA); 00049 00050 als = (alsData < alsLim); 00051 00052 if (proxData) { 00053 if (!lastProx) { 00054 tog = !tog; 00055 } 00056 lastProx = true; 00057 offDelay = 250; 00058 dly = false; 00059 } else { 00060 lastProx = false; 00061 } 00062 if (offDelay > 0) { 00063 offDelay -= 1; 00064 } else { 00065 dly = true; 00066 } 00067 } 00068 }
Generated on Mon Jul 18 2022 21:54:37 by
1.7.2

Ambient Light and Proximity Sensor MAX44000