
Rohm BH1745 red-green-blue-clear -color sensor hello world. Uses Rohm sensor hal for i2c commands and rohm-bh1745 -driver for sensor specific commands.
Dependencies: mbed rohm-bh1745 rohm-sensor-hal
Fork of rohm-rpr0521-hello by
main_classic.cpp@6:cdf8e9ef435d, 2016-09-20 (annotated)
- Committer:
- MikkoZ
- Date:
- Tue Sep 20 11:20:22 2016 +0000
- Revision:
- 6:cdf8e9ef435d
- Parent:
- 4:a9efa968de28
Refactored main.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikkoZ | 2:edc916d1a86d | 1 | /* Copyright 2016 Rohm Semiconductor |
MikkoZ | 2:edc916d1a86d | 2 | |
MikkoZ | 2:edc916d1a86d | 3 | Licensed under the Apache License, Version 2.0 (the "License"); |
MikkoZ | 2:edc916d1a86d | 4 | you may not use this file except in compliance with the License. |
MikkoZ | 2:edc916d1a86d | 5 | You may obtain a copy of the License at |
MikkoZ | 2:edc916d1a86d | 6 | |
MikkoZ | 2:edc916d1a86d | 7 | http://www.apache.org/licenses/LICENSE-2.0 |
MikkoZ | 2:edc916d1a86d | 8 | |
MikkoZ | 2:edc916d1a86d | 9 | Unless required by applicable law or agreed to in writing, software |
MikkoZ | 2:edc916d1a86d | 10 | distributed under the License is distributed on an "AS IS" BASIS, |
MikkoZ | 2:edc916d1a86d | 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
MikkoZ | 2:edc916d1a86d | 12 | See the License for the specific language governing permissions and |
MikkoZ | 2:edc916d1a86d | 13 | limitations under the License. |
MikkoZ | 2:edc916d1a86d | 14 | */ |
MikkoZ | 2:edc916d1a86d | 15 | |
MikkoZ | 2:edc916d1a86d | 16 | #include "rohm-sensor-hal/rohm-sensor-hal/rohm_hal.h" //mbed.h, types, DEBUG_print* |
MikkoZ | 2:edc916d1a86d | 17 | #include "rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h" |
MikkoZ | 2:edc916d1a86d | 18 | |
MikkoZ | 4:a9efa968de28 | 19 | #include "rohm-bh1745/rohm-bh1745/bh1745_driver.h" |
MikkoZ | 4:a9efa968de28 | 20 | #include "rohm-bh1745/rohm-bh1745/bh1745.h" |
MikkoZ | 2:edc916d1a86d | 21 | |
MikkoZ | 2:edc916d1a86d | 22 | Serial pc(USBTX, USBRX); |
MikkoZ | 2:edc916d1a86d | 23 | |
MikkoZ | 6:cdf8e9ef435d | 24 | void bh1745_print_one_value(){ |
MikkoZ | 6:cdf8e9ef435d | 25 | bool error; |
MikkoZ | 6:cdf8e9ef435d | 26 | uint16_t data[4]; //4 channels of 16-bit data |
MikkoZ | 6:cdf8e9ef435d | 27 | |
MikkoZ | 6:cdf8e9ef435d | 28 | error = bh1745_read_data(&data[0]); |
MikkoZ | 6:cdf8e9ef435d | 29 | if (!error) { |
MikkoZ | 6:cdf8e9ef435d | 30 | pc.printf("Red[%4u], Green[%4u], Blue[%4u], Clear[%4u]\n\r", data[0], data[1], data[2], data[3]); |
MikkoZ | 6:cdf8e9ef435d | 31 | } |
MikkoZ | 6:cdf8e9ef435d | 32 | else { |
MikkoZ | 6:cdf8e9ef435d | 33 | pc.printf("\n\r"); |
MikkoZ | 6:cdf8e9ef435d | 34 | } |
MikkoZ | 6:cdf8e9ef435d | 35 | } |
MikkoZ | 6:cdf8e9ef435d | 36 | |
MikkoZ | 4:a9efa968de28 | 37 | void bh1745_print_raw_values(){ |
MikkoZ | 4:a9efa968de28 | 38 | pc.printf("\nbh1745 library test program.\n\r"); |
MikkoZ | 2:edc916d1a86d | 39 | I2CCommonBegin(); |
MikkoZ | 2:edc916d1a86d | 40 | |
MikkoZ | 4:a9efa968de28 | 41 | bh1745_wait_until_found(); |
MikkoZ | 2:edc916d1a86d | 42 | pc.printf("\nSensor found.\n\r"); |
MikkoZ | 4:a9efa968de28 | 43 | bh1745_initial_setup(); |
MikkoZ | 2:edc916d1a86d | 44 | wait(1); |
MikkoZ | 2:edc916d1a86d | 45 | |
MikkoZ | 2:edc916d1a86d | 46 | while(1) { |
MikkoZ | 6:cdf8e9ef435d | 47 | bh1745_print_one_value(); |
MikkoZ | 4:a9efa968de28 | 48 | wait(0.2); |
MikkoZ | 2:edc916d1a86d | 49 | } |
MikkoZ | 2:edc916d1a86d | 50 | } |
MikkoZ | 2:edc916d1a86d | 51 | |
MikkoZ | 2:edc916d1a86d | 52 | |
MikkoZ | 2:edc916d1a86d | 53 | int main() { |
MikkoZ | 4:a9efa968de28 | 54 | bh1745_print_raw_values(); |
MikkoZ | 2:edc916d1a86d | 55 | } |
MikkoZ | 2:edc916d1a86d | 56 |