LED Demo with proximity sensor support for nexpaq development system

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Prox_Demo by Maxim nexpaq

LED 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 sending the information back to the application running on the phone, and the phone 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

Committer:
nexpaq
Date:
Fri Sep 23 18:53:57 2016 +0000
Revision:
7:85c8f02ae327
Parent:
5:7d8e69b1d3b6
Child:
8:42704f06a339
Added PWM support to LEDs.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 0:b86eda0e990d 1 #include "mbed.h"
nexpaq 0:b86eda0e990d 2 #include "nexpaq_mdk.h"
nexpaq 5:7d8e69b1d3b6 3 #include "MAX44000.h"
nexpaq 0:b86eda0e990d 4
jowen 2:3842948024ca 5 #ifdef __cplusplus
jowen 2:3842948024ca 6 extern "C" {
jowen 2:3842948024ca 7 #endif
jowen 2:3842948024ca 8 extern volatile uint8_t flag_jump_bsl;
jowen 2:3842948024ca 9 #ifdef __cplusplus
jowen 2:3842948024ca 10 }
jowen 2:3842948024ca 11 #endif
nexpaq 5:7d8e69b1d3b6 12
nexpaq 5:7d8e69b1d3b6 13 MAX44000 max44000(P1_6, P1_7);
nexpaq 7:85c8f02ae327 14 PwmOut ledR(P2_4);
nexpaq 7:85c8f02ae327 15 PwmOut ledG(P2_5);
nexpaq 7:85c8f02ae327 16 PwmOut ledB(P2_6);
nexpaq 0:b86eda0e990d 17 DigitalIn button(P0_1, PullUp);
nexpaq 0:b86eda0e990d 18
nexpaq 0:b86eda0e990d 19 /***** Definitions *****/
nexpaq 0:b86eda0e990d 20 #define FUNCTION_TABLE_NUM 1
nexpaq 0:b86eda0e990d 21 #define UUID_NUM 16 //UUID number is 16, don't change it
nexpaq 4:494741f7f5b2 22 #define LOOP_DELAY 100
nexpaq 5:7d8e69b1d3b6 23 #define PROX_THRESHOLD 50
nexpaq 0:b86eda0e990d 24
nexpaq 0:b86eda0e990d 25 /***** Globals *****/
nexpaq 0:b86eda0e990d 26 void my_function_CMD_2700(unsigned char *pData, unsigned char len);
nexpaq 0:b86eda0e990d 27 const MDK_REGISTER_CMD my_cmd_func_table[FUNCTION_TABLE_NUM] = {
nexpaq 0:b86eda0e990d 28 {0x2700, my_function_CMD_2700}, // Command -> function
nexpaq 0:b86eda0e990d 29 };
nexpaq 0:b86eda0e990d 30
nexpaq 5:7d8e69b1d3b6 31 int lastPrx = 0;
nexpaq 5:7d8e69b1d3b6 32 unsigned char prxPress = 0x02;
gsteiert 3:9d15891f9352 33 int lastBtn = 1;
nexpaq 0:b86eda0e990d 34 unsigned char btnPress = 0x01;
nexpaq 0:b86eda0e990d 35
nexpaq 0:b86eda0e990d 36 /***** Functions *****/
nexpaq 0:b86eda0e990d 37 void my_function_CMD_2700(unsigned char *pData, unsigned char len){
nexpaq 0:b86eda0e990d 38 unsigned char response = 0x00;
nexpaq 7:85c8f02ae327 39 ledR = 1.0f - (pData[0] / 255.0f);
nexpaq 7:85c8f02ae327 40 ledG = 1.0f - (pData[1] / 255.0f);
nexpaq 7:85c8f02ae327 41 ledB = 1.0f - (pData[2] / 255.0f);
nexpaq 0:b86eda0e990d 42 np_api_upload(0x2701, &response, 1);
nexpaq 0:b86eda0e990d 43 }
nexpaq 0:b86eda0e990d 44
nexpaq 0:b86eda0e990d 45 /******************************************************************************/
nexpaq 0:b86eda0e990d 46 void app_setup(){
nexpaq 0:b86eda0e990d 47 if ( np_api_register((MDK_REGISTER_CMD*)my_cmd_func_table, FUNCTION_TABLE_NUM) == MDK_REGISTER_FAILD ) {
nexpaq 0:b86eda0e990d 48 // Register failed handle code
nexpaq 0:b86eda0e990d 49 error("MDK Register Failed");
nexpaq 0:b86eda0e990d 50 }
nexpaq 5:7d8e69b1d3b6 51 max44000.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_64X, MAX44000::ALSPGA_1X, MAX44000::DRV_110);
nexpaq 7:85c8f02ae327 52 ledR = 1.0f;
nexpaq 7:85c8f02ae327 53 ledG = 1.0f;
nexpaq 7:85c8f02ae327 54 ledB = 1.0f;
nexpaq 0:b86eda0e990d 55 }
nexpaq 0:b86eda0e990d 56
nexpaq 0:b86eda0e990d 57 void app_loop() {
nexpaq 5:7d8e69b1d3b6 58 int proxData = max44000.readReg(MAX44000::REG_PRX_DATA);
nexpaq 5:7d8e69b1d3b6 59 if (proxData > PROX_THRESHOLD) {
nexpaq 5:7d8e69b1d3b6 60 if (!lastPrx) {
nexpaq 5:7d8e69b1d3b6 61 np_api_upload(0x2800, &prxPress, 1);
nexpaq 5:7d8e69b1d3b6 62 }
nexpaq 5:7d8e69b1d3b6 63 lastPrx = 1;
nexpaq 5:7d8e69b1d3b6 64 } else {
nexpaq 5:7d8e69b1d3b6 65 lastPrx = 0;
nexpaq 5:7d8e69b1d3b6 66 }
nexpaq 5:7d8e69b1d3b6 67
gsteiert 3:9d15891f9352 68 if (!button && lastBtn) {
gsteiert 3:9d15891f9352 69 np_api_upload(0x2800, &btnPress, 1);
gsteiert 3:9d15891f9352 70 }
gsteiert 3:9d15891f9352 71 lastBtn = button;
nexpaq 0:b86eda0e990d 72 }
nexpaq 0:b86eda0e990d 73
nexpaq 0:b86eda0e990d 74 int main(void){
jowen 2:3842948024ca 75
nexpaq 0:b86eda0e990d 76 np_api_init();
nexpaq 0:b86eda0e990d 77 app_setup();
nexpaq 0:b86eda0e990d 78 np_api_start();
nexpaq 5:7d8e69b1d3b6 79
nexpaq 0:b86eda0e990d 80 while(1){
gsteiert 3:9d15891f9352 81 Thread::wait(LOOP_DELAY);
nexpaq 0:b86eda0e990d 82 app_loop();
nexpaq 0:b86eda0e990d 83 np_api_bsl_chk();
nexpaq 0:b86eda0e990d 84 }
jowen 2:3842948024ca 85
nexpaq 0:b86eda0e990d 86 return 0;
nexpaq 0:b86eda0e990d 87 }
nexpaq 0:b86eda0e990d 88