dhgdh
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
main.cpp@7:04a9ea641c79, 2016-10-21 (annotated)
- Committer:
- cyberjoey
- Date:
- Fri Oct 21 20:19:04 2016 +0000
- Revision:
- 7:04a9ea641c79
- Parent:
- 6:7b51d2ebef23
- Child:
- 8:782d1dcdfd94
BUZZAH BITCHES
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 0:b86eda0e990d | 1 | #include "mbed.h" |
nexpaq | 0:b86eda0e990d | 2 | #include "nexpaq_mdk.h" |
cyberjoey | 7:04a9ea641c79 | 3 | #include "MAX44000.h" |
cyberjoey | 7:04a9ea641c79 | 4 | #include "pwm_tone.h" |
cyberjoey | 7:04a9ea641c79 | 5 | |
cyberjoey | 7:04a9ea641c79 | 6 | //MAX44000 max44000(P1_6, P1_7); |
cyberjoey | 7:04a9ea641c79 | 7 | //i2c code goes here//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
cyberjoey | 7:04a9ea641c79 | 8 | I2C i2c(P1_6,P1_7); |
cyberjoey | 7:04a9ea641c79 | 9 | PwmOut ledR(P2_4); |
cyberjoey | 7:04a9ea641c79 | 10 | PwmOut ledG(P2_5); |
cyberjoey | 7:04a9ea641c79 | 11 | PwmOut ledB(P2_6); |
cyberjoey | 7:04a9ea641c79 | 12 | PwmOut Buzzer(P1_2); |
nexpaq | 0:b86eda0e990d | 13 | DigitalIn button(P0_1, PullUp); |
cyberjoey | 7:04a9ea641c79 | 14 | //DigitalOut buz(P0_0); |
nexpaq | 0:b86eda0e990d | 15 | |
cyberjoey | 7:04a9ea641c79 | 16 | //int buzzing=0; |
cyberjoey | 7:04a9ea641c79 | 17 | |
nexpaq | 0:b86eda0e990d | 18 | /***** Definitions *****/ |
cyberjoey | 7:04a9ea641c79 | 19 | #define FUNCTION_TABLE_NUM 1 |
cyberjoey | 7:04a9ea641c79 | 20 | #define UUID_NUM 16 //UUID number is 16, don't change it |
nexpaq | 4:494741f7f5b2 | 21 | #define LOOP_DELAY 100 |
cyberjoey | 7:04a9ea641c79 | 22 | #define PROX_THRESHOLD 50 |
cyberjoey | 7:04a9ea641c79 | 23 | |
nexpaq | 0:b86eda0e990d | 24 | /***** Globals *****/ |
nexpaq | 0:b86eda0e990d | 25 | void my_function_CMD_2700(unsigned char *pData, unsigned char len); |
nexpaq | 0:b86eda0e990d | 26 | const MDK_REGISTER_CMD my_cmd_func_table[FUNCTION_TABLE_NUM] = { |
cyberjoey | 7:04a9ea641c79 | 27 | {0x2700, my_function_CMD_2700}, // Command -> function |
nexpaq | 0:b86eda0e990d | 28 | }; |
cyberjoey | 7:04a9ea641c79 | 29 | |
cyberjoey | 7:04a9ea641c79 | 30 | //int lastPrx = 0; |
cyberjoey | 7:04a9ea641c79 | 31 | int toggle = 0; |
cyberjoey | 7:04a9ea641c79 | 32 | unsigned char prxPress = 0x02; |
gsteiert | 3:9d15891f9352 | 33 | int lastBtn = 1; |
nexpaq | 0:b86eda0e990d | 34 | unsigned char btnPress = 0x01; |
cyberjoey | 7:04a9ea641c79 | 35 | |
nexpaq | 0:b86eda0e990d | 36 | /***** Functions *****/ |
nexpaq | 6:7b51d2ebef23 | 37 | void my_function_CMD_2700(unsigned char *pData, unsigned char len) |
nexpaq | 6:7b51d2ebef23 | 38 | { |
nexpaq | 6:7b51d2ebef23 | 39 | unsigned char response = 0x00; |
cyberjoey | 7:04a9ea641c79 | 40 | ledR = 1.0f - (pData[0] / 255.0f); |
cyberjoey | 7:04a9ea641c79 | 41 | ledG = 1.0f - (pData[1] / 255.0f); |
cyberjoey | 7:04a9ea641c79 | 42 | ledB = 1.0f - (pData[2] / 255.0f); |
nexpaq | 6:7b51d2ebef23 | 43 | np_api_upload(0x2701, &response, 1); |
nexpaq | 0:b86eda0e990d | 44 | } |
nexpaq | 0:b86eda0e990d | 45 | |
cyberjoey | 7:04a9ea641c79 | 46 | int i2c_read_gesture() |
cyberjoey | 7:04a9ea641c79 | 47 | { |
cyberjoey | 7:04a9ea641c79 | 48 | char readVal; |
cyberjoey | 7:04a9ea641c79 | 49 | char gestReg; |
cyberjoey | 7:04a9ea641c79 | 50 | |
cyberjoey | 7:04a9ea641c79 | 51 | gestReg = 0x04; |
cyberjoey | 7:04a9ea641c79 | 52 | |
cyberjoey | 7:04a9ea641c79 | 53 | i2c.write( 0x20, &gestReg, 1 ); |
cyberjoey | 7:04a9ea641c79 | 54 | i2c.read( 0x20, &readVal, 1 ); |
cyberjoey | 7:04a9ea641c79 | 55 | |
cyberjoey | 7:04a9ea641c79 | 56 | //perform cast here |
cyberjoey | 7:04a9ea641c79 | 57 | return( readVal ); |
cyberjoey | 7:04a9ea641c79 | 58 | } |
cyberjoey | 7:04a9ea641c79 | 59 | |
nexpaq | 0:b86eda0e990d | 60 | /******************************************************************************/ |
nexpaq | 6:7b51d2ebef23 | 61 | void app_setup() |
nexpaq | 6:7b51d2ebef23 | 62 | { |
nexpaq | 6:7b51d2ebef23 | 63 | if ( np_api_register((MDK_REGISTER_CMD*)my_cmd_func_table, FUNCTION_TABLE_NUM) == MDK_REGISTER_FAILD ) { |
nexpaq | 6:7b51d2ebef23 | 64 | // Register failed handle code |
nexpaq | 6:7b51d2ebef23 | 65 | error("MDK Register Failed"); |
nexpaq | 6:7b51d2ebef23 | 66 | } |
cyberjoey | 7:04a9ea641c79 | 67 | //max44000.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_64X, MAX44000::ALSPGA_1X, MAX44000::DRV_110); |
cyberjoey | 7:04a9ea641c79 | 68 | ledR = 1.0f; |
cyberjoey | 7:04a9ea641c79 | 69 | ledG = 1.0f; |
cyberjoey | 7:04a9ea641c79 | 70 | ledB = 1.0f; |
cyberjoey | 7:04a9ea641c79 | 71 | |
cyberjoey | 7:04a9ea641c79 | 72 | //buz = 0; |
nexpaq | 0:b86eda0e990d | 73 | } |
cyberjoey | 7:04a9ea641c79 | 74 | |
nexpaq | 6:7b51d2ebef23 | 75 | void app_loop() |
nexpaq | 6:7b51d2ebef23 | 76 | { |
cyberjoey | 7:04a9ea641c79 | 77 | float A_4 = 1000000/Do4; |
cyberjoey | 7:04a9ea641c79 | 78 | //int proxData = max44000.readReg(MAX44000::REG_PRX_DATA); |
cyberjoey | 7:04a9ea641c79 | 79 | int gesture = i2c_read_gesture(); |
cyberjoey | 7:04a9ea641c79 | 80 | if (gesture == 0x01) { |
cyberjoey | 7:04a9ea641c79 | 81 | if (!toggle) { |
cyberjoey | 7:04a9ea641c79 | 82 | np_api_upload(0x2800, &prxPress, 1); |
cyberjoey | 7:04a9ea641c79 | 83 | //Stop_tunes(Buzzer); |
cyberjoey | 7:04a9ea641c79 | 84 | } |
cyberjoey | 7:04a9ea641c79 | 85 | toggle = 1; |
cyberjoey | 7:04a9ea641c79 | 86 | |
cyberjoey | 7:04a9ea641c79 | 87 | } else if (gesture == 0x02) { |
cyberjoey | 7:04a9ea641c79 | 88 | if(toggle){ |
cyberjoey | 7:04a9ea641c79 | 89 | np_api_upload(0x2800, &prxPress, 1); |
cyberjoey | 7:04a9ea641c79 | 90 | //Tune(Buzzer, A_4, 4); //4 Octave C beat 4/16 |
cyberjoey | 7:04a9ea641c79 | 91 | } |
cyberjoey | 7:04a9ea641c79 | 92 | toggle = 0;} |
cyberjoey | 7:04a9ea641c79 | 93 | |
cyberjoey | 7:04a9ea641c79 | 94 | if(toggle) |
cyberjoey | 7:04a9ea641c79 | 95 | Tune(Buzzer, A_4, 4); //4 Octave C beat 4/16 |
cyberjoey | 7:04a9ea641c79 | 96 | /* |
cyberjoey | 7:04a9ea641c79 | 97 | if(toggle && (gesture==0x03)) |
cyberjoey | 7:04a9ea641c79 | 98 | buzzing=1; |
cyberjoey | 7:04a9ea641c79 | 99 | |
cyberjoey | 7:04a9ea641c79 | 100 | if(buzzing && gesture == 0x05) |
cyberjoey | 7:04a9ea641c79 | 101 | buzzing = 0; |
cyberjoey | 7:04a9ea641c79 | 102 | |
cyberjoey | 7:04a9ea641c79 | 103 | if(buzzing){ |
cyberjoey | 7:04a9ea641c79 | 104 | if(!buz){ |
cyberjoey | 7:04a9ea641c79 | 105 | buz=1;} |
cyberjoey | 7:04a9ea641c79 | 106 | else{ |
cyberjoey | 7:04a9ea641c79 | 107 | buz=0;} |
cyberjoey | 7:04a9ea641c79 | 108 | }*/ |
cyberjoey | 7:04a9ea641c79 | 109 | |
nexpaq | 6:7b51d2ebef23 | 110 | if (!button && lastBtn) { |
gsteiert | 3:9d15891f9352 | 111 | np_api_upload(0x2800, &btnPress, 1); |
nexpaq | 6:7b51d2ebef23 | 112 | } |
nexpaq | 6:7b51d2ebef23 | 113 | lastBtn = button; |
nexpaq | 0:b86eda0e990d | 114 | } |
nexpaq | 0:b86eda0e990d | 115 | |
cyberjoey | 7:04a9ea641c79 | 116 | |
cyberjoey | 7:04a9ea641c79 | 117 | |
nexpaq | 6:7b51d2ebef23 | 118 | int main(void) |
nexpaq | 6:7b51d2ebef23 | 119 | { |
cyberjoey | 7:04a9ea641c79 | 120 | |
nexpaq | 6:7b51d2ebef23 | 121 | np_api_init(); |
nexpaq | 6:7b51d2ebef23 | 122 | app_setup(); |
nexpaq | 6:7b51d2ebef23 | 123 | np_api_start(); |
nexpaq | 6:7b51d2ebef23 | 124 | while(1) { |
cyberjoey | 7:04a9ea641c79 | 125 | |
nexpaq | 6:7b51d2ebef23 | 126 | Thread::wait(LOOP_DELAY); |
nexpaq | 6:7b51d2ebef23 | 127 | app_loop(); |
nexpaq | 6:7b51d2ebef23 | 128 | np_api_bsl_chk(); |
cyberjoey | 7:04a9ea641c79 | 129 | |
nexpaq | 6:7b51d2ebef23 | 130 | } |
cyberjoey | 7:04a9ea641c79 | 131 | |
nexpaq | 6:7b51d2ebef23 | 132 | return 0; |
cyberjoey | 7:04a9ea641c79 | 133 | } |