dhgdh
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
main.cpp
- Committer:
- cyberjoey
- Date:
- 2016-10-21
- Revision:
- 7:04a9ea641c79
- Parent:
- 6:7b51d2ebef23
- Child:
- 8:782d1dcdfd94
File content as of revision 7:04a9ea641c79:
#include "mbed.h"
#include "nexpaq_mdk.h"
#include "MAX44000.h"
#include "pwm_tone.h"
//MAX44000 max44000(P1_6, P1_7);
//i2c code goes here////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I2C i2c(P1_6,P1_7);
PwmOut ledR(P2_4);
PwmOut ledG(P2_5);
PwmOut ledB(P2_6);
PwmOut Buzzer(P1_2);
DigitalIn button(P0_1, PullUp);
//DigitalOut buz(P0_0);
//int buzzing=0;
/***** Definitions *****/
#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);
const MDK_REGISTER_CMD my_cmd_func_table[FUNCTION_TABLE_NUM] = {
{0x2700, my_function_CMD_2700}, // Command -> function
};
//int lastPrx = 0;
int toggle = 0;
unsigned char prxPress = 0x02;
int lastBtn = 1;
unsigned char btnPress = 0x01;
/***** Functions *****/
void my_function_CMD_2700(unsigned char *pData, unsigned char len)
{
unsigned char response = 0x00;
ledR = 1.0f - (pData[0] / 255.0f);
ledG = 1.0f - (pData[1] / 255.0f);
ledB = 1.0f - (pData[2] / 255.0f);
np_api_upload(0x2701, &response, 1);
}
int i2c_read_gesture()
{
char readVal;
char gestReg;
gestReg = 0x04;
i2c.write( 0x20, &gestReg, 1 );
i2c.read( 0x20, &readVal, 1 );
//perform cast here
return( readVal );
}
/******************************************************************************/
void app_setup()
{
if ( np_api_register((MDK_REGISTER_CMD*)my_cmd_func_table, FUNCTION_TABLE_NUM) == MDK_REGISTER_FAILD ) {
// Register failed handle code
error("MDK Register Failed");
}
//max44000.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_64X, MAX44000::ALSPGA_1X, MAX44000::DRV_110);
ledR = 1.0f;
ledG = 1.0f;
ledB = 1.0f;
//buz = 0;
}
void app_loop()
{
float A_4 = 1000000/Do4;
//int proxData = max44000.readReg(MAX44000::REG_PRX_DATA);
int gesture = i2c_read_gesture();
if (gesture == 0x01) {
if (!toggle) {
np_api_upload(0x2800, &prxPress, 1);
//Stop_tunes(Buzzer);
}
toggle = 1;
} else if (gesture == 0x02) {
if(toggle){
np_api_upload(0x2800, &prxPress, 1);
//Tune(Buzzer, A_4, 4); //4 Octave C beat 4/16
}
toggle = 0;}
if(toggle)
Tune(Buzzer, A_4, 4); //4 Octave C beat 4/16
/*
if(toggle && (gesture==0x03))
buzzing=1;
if(buzzing && gesture == 0x05)
buzzing = 0;
if(buzzing){
if(!buz){
buz=1;}
else{
buz=0;}
}*/
if (!button && lastBtn) {
np_api_upload(0x2800, &btnPress, 1);
}
lastBtn = button;
}
int main(void)
{
np_api_init();
app_setup();
np_api_start();
while(1) {
Thread::wait(LOOP_DELAY);
app_loop();
np_api_bsl_chk();
}
return 0;
}
