Proximity / Ambient Light Sensor LED Demo

Dependencies:   MAX44000 nexpaq_mdk

Fork of ALS_Prox_Demo by Maxim nexpaq

ALS Prox Demo

MAX32625NEXPAQ development module

This project is a demonstration application for the MAX32625NEXPAQ development module. You will need the nexpaq application and a compatible phone to run this demo, along with the MAX44000PMB1# peripheral module. This project demonstrates polling the proximity sensor to use it like a button and also polling the ambient light sensor and sending the information back to the application running on the phone, and the phone controlling the threshold for the proximity sensor and controlling the on board RGB LED to create different colors.

Go to the nexpaq developers hub for details on how to load the code for the tile into the application.

Resources

Revision:
5:7d8e69b1d3b6
Parent:
4:494741f7f5b2
Child:
6:eb5c0139e5db
--- a/main.cpp	Mon Sep 19 14:21:15 2016 +0000
+++ b/main.cpp	Mon Sep 19 14:50:49 2016 +0000
@@ -1,5 +1,6 @@
 #include "mbed.h"
 #include "nexpaq_mdk.h"
+#include "MAX44000.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -8,6 +9,8 @@
 #ifdef __cplusplus
 }
 #endif
+
+MAX44000 max44000(P1_6, P1_7);
 DigitalOut ledR(P2_4, LED_OFF);
 DigitalOut ledG(P2_5, LED_OFF);
 DigitalOut ledB(P2_6, LED_OFF);
@@ -17,6 +20,7 @@
 #define		FUNCTION_TABLE_NUM					1
 #define		UUID_NUM							16			//UUID number is 16, don't change it
 #define     LOOP_DELAY                          100
+#define     PROX_THRESHOLD                      50
 
 /***** Globals *****/
 void my_function_CMD_2700(unsigned char *pData, unsigned char len);
@@ -24,6 +28,8 @@
 		{0x2700, my_function_CMD_2700},		// Command -> function
 };
 
+int lastPrx = 0;
+unsigned char prxPress = 0x02;
 int lastBtn = 1;
 unsigned char btnPress = 0x01;
 
@@ -42,9 +48,20 @@
 		// Register failed handle code
 		error("MDK Register Failed");
 	}
+    max44000.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_64X, MAX44000::ALSPGA_1X, MAX44000::DRV_110);	
 }
 
 void app_loop() {
+    int proxData = max44000.readReg(MAX44000::REG_PRX_DATA);
+    if (proxData > PROX_THRESHOLD) {
+    	if (!lastPrx) {
+            np_api_upload(0x2800, &prxPress, 1);
+        }
+        lastPrx = 1;
+    } else {
+    	lastPrx = 0;
+    }
+
 	if (!button && lastBtn) {
         np_api_upload(0x2800, &btnPress, 1);
 	}	
@@ -56,6 +73,7 @@
 	np_api_init();
 	app_setup();
 	np_api_start();	
+
 	while(1){
     	Thread::wait(LOOP_DELAY);
 		app_loop();