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:
switches
Date:
Sat Feb 04 03:32:10 2017 +0000
Revision:
12:c2d209c1fdc1
Parent:
9:ab02ac0fe404
Replaced development library with official mbed libarary

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