S11059-02DTカラーセンサーのライブラリ
Diff: Color.h
- Revision:
- 0:2bb06ba9bace
- Child:
- 1:815b206c14fb
diff -r 000000000000 -r 2bb06ba9bace Color.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Color.h Tue Nov 16 08:22:01 2021 +0000 @@ -0,0 +1,41 @@ +//S11059-02DTカラーセンサー用のライブラリ +#include "mbed.h" + +#define ADDR (0x2A<<1)//センサーのアドレス +#define CTRL 0x00//コントロールレジスタ +#define READ 0x03//読み込む場所 +#define RESET 0x89//ADCリセットとスリープ解除 + +class Color{ + private: + I2C &i2c_handle_;//通信のハンドル + char data_[8];//データを受信 + public: + Color(I2C &i2c_handle,uint8_t cmd);//cmdは積分時間などの設定 + void update();//データの更新 + uint16_t r();//赤のパラメータ + uint16_t g();//緑のパラメータ + uint16_t b();//青のパラメータ + uint16_t ir();//赤外線のパラメータ +}; +/**使用例 +#include "mbed.h" +#include "Color.h" + +Serial pc(USBTX,USBRX); +I2C handle(PB_9,PB_8); + +int main() +{ + Color color(handle,0x0B); + while(1) { + color.update(); + int R=color.r(); + int G=color.g(); + int B=color.b(); + int IR=color.ir(); + printf("R=%d G=%d B=%d IR=%d\r\n",R,G,B,IR); + wait(1); + } +} +*/ \ No newline at end of file