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 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
Diff: main.cpp
- Revision:
- 7:04a9ea641c79
- Parent:
- 6:7b51d2ebef23
- Child:
- 8:782d1dcdfd94
--- a/main.cpp Sat Oct 15 18:47:18 2016 +0000
+++ b/main.cpp Fri Oct 21 20:19:04 2016 +0000
@@ -1,35 +1,62 @@
#include "mbed.h"
#include "nexpaq_mdk.h"
-
-DigitalOut ledR(P2_4, LED_OFF);
-DigitalOut ledG(P2_5, LED_OFF);
-DigitalOut ledB(P2_6, LED_OFF);
+#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 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
+ {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 = (pData[0]>0) ? LED_ON : LED_OFF ;
- ledG = (pData[1]>0) ? LED_ON : LED_OFF ;
- ledB = (pData[2]>0) ? LED_ON : LED_OFF ;
+ 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()
{
@@ -37,28 +64,70 @@
// 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;
-}
-
+}
\ No newline at end of file
