![](/media/cache/group/IMG_1289.JPG.50x50_q85.jpg)
Test program for MAX44008
main.cpp@0:0ddeaec701e0, 2015-12-22 (annotated)
- Committer:
- Rhyme
- Date:
- Tue Dec 22 06:05:42 2015 +0000
- Revision:
- 0:0ddeaec701e0
commit before publishing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:0ddeaec701e0 | 1 | #include "mbed.h" |
Rhyme | 0:0ddeaec701e0 | 2 | #include "MAX44008.h" |
Rhyme | 0:0ddeaec701e0 | 3 | |
Rhyme | 0:0ddeaec701e0 | 4 | #define MAX44008_I2C_ADDRESS (0x41) |
Rhyme | 0:0ddeaec701e0 | 5 | |
Rhyme | 0:0ddeaec701e0 | 6 | #if defined (TARGET_KL25Z) |
Rhyme | 0:0ddeaec701e0 | 7 | #define PIN_SCL PTE1 |
Rhyme | 0:0ddeaec701e0 | 8 | #define PIN_SDA PTE0 |
Rhyme | 0:0ddeaec701e0 | 9 | #elif defined (TARGET_KL46Z) |
Rhyme | 0:0ddeaec701e0 | 10 | #define PIN_SCL PTE1 |
Rhyme | 0:0ddeaec701e0 | 11 | #define PIN_SDA PTE0 |
Rhyme | 0:0ddeaec701e0 | 12 | #elif defined (TARGET_K64F) |
Rhyme | 0:0ddeaec701e0 | 13 | #define PIN_SCL PTE24 |
Rhyme | 0:0ddeaec701e0 | 14 | #define PIN_SDA PTE25 |
Rhyme | 0:0ddeaec701e0 | 15 | #elif defined (TARGET_K22F) |
Rhyme | 0:0ddeaec701e0 | 16 | #define PIN_SCL PTE1 |
Rhyme | 0:0ddeaec701e0 | 17 | #define PIN_SDA PTE0 |
Rhyme | 0:0ddeaec701e0 | 18 | #elif defined (TARGET_KL05Z) |
Rhyme | 0:0ddeaec701e0 | 19 | #define PIN_SCL PTB3 |
Rhyme | 0:0ddeaec701e0 | 20 | #define PIN_SDA PTB4 |
Rhyme | 0:0ddeaec701e0 | 21 | #elif define (TARGET_F411RE) |
Rhyme | 0:0ddeaec701e0 | 22 | #define PIN_SCL PB_8 |
Rhyme | 0:0ddeaec701e0 | 23 | #define PIN_SDA PB_9 |
Rhyme | 0:0ddeaec701e0 | 24 | #else |
Rhyme | 0:0ddeaec701e0 | 25 | #error TARGET NOT DEFINED |
Rhyme | 0:0ddeaec701e0 | 26 | #endif |
Rhyme | 0:0ddeaec701e0 | 27 | |
Rhyme | 0:0ddeaec701e0 | 28 | MAX44008 *max44008 = 0 ; |
Rhyme | 0:0ddeaec701e0 | 29 | |
Rhyme | 0:0ddeaec701e0 | 30 | void reportMAX44008(MAX44008 *max44008) |
Rhyme | 0:0ddeaec701e0 | 31 | { |
Rhyme | 0:0ddeaec701e0 | 32 | uint16_t amb_c, amb_r, amb_g, amb_b, amb_ir, amb_ircomp, amb_temp ; |
Rhyme | 0:0ddeaec701e0 | 33 | amb_c = max44008->getAMB_CLEAR() ; |
Rhyme | 0:0ddeaec701e0 | 34 | amb_r = max44008->getAMB_RED() ; |
Rhyme | 0:0ddeaec701e0 | 35 | amb_g = max44008->getAMB_GREEN() ; |
Rhyme | 0:0ddeaec701e0 | 36 | amb_b = max44008->getAMB_BLUE() ; |
Rhyme | 0:0ddeaec701e0 | 37 | amb_ir = max44008->getIR() ; |
Rhyme | 0:0ddeaec701e0 | 38 | amb_ircomp = max44008->getIRCOMP() ; |
Rhyme | 0:0ddeaec701e0 | 39 | amb_temp = max44008->getTEMP() ; |
Rhyme | 0:0ddeaec701e0 | 40 | printf("--- MAX44008 ---\n") ; |
Rhyme | 0:0ddeaec701e0 | 41 | printf(" C[ %04X ]\n", amb_c) ; |
Rhyme | 0:0ddeaec701e0 | 42 | printf("R[ %04X ] G[ %04X ] B[ %04X ]\n",amb_r, amb_g, amb_b) ; |
Rhyme | 0:0ddeaec701e0 | 43 | printf("IR[ %04X ] IRCOMP [ %04X ]\n",amb_ir, amb_ircomp) ; |
Rhyme | 0:0ddeaec701e0 | 44 | printf(" TEMP [ %04X ]\n",amb_temp) ; |
Rhyme | 0:0ddeaec701e0 | 45 | printf("\n") ; |
Rhyme | 0:0ddeaec701e0 | 46 | } |
Rhyme | 0:0ddeaec701e0 | 47 | |
Rhyme | 0:0ddeaec701e0 | 48 | #define MODE_CLEAR_RGB_IR 0x02 |
Rhyme | 0:0ddeaec701e0 | 49 | |
Rhyme | 0:0ddeaec701e0 | 50 | int main() { |
Rhyme | 0:0ddeaec701e0 | 51 | max44008 = new MAX44008(PIN_SDA, PIN_SCL, MAX44008_I2C_ADDRESS) ; |
Rhyme | 0:0ddeaec701e0 | 52 | max44008->setMode(MODE_CLEAR_RGB_IR) ; |
Rhyme | 0:0ddeaec701e0 | 53 | |
Rhyme | 0:0ddeaec701e0 | 54 | while(1) { |
Rhyme | 0:0ddeaec701e0 | 55 | reportMAX44008(max44008) ; |
Rhyme | 0:0ddeaec701e0 | 56 | wait(1) ; |
Rhyme | 0:0ddeaec701e0 | 57 | } |
Rhyme | 0:0ddeaec701e0 | 58 | } |