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.
Diff: Color.cpp
- Revision:
- 0:2bb06ba9bace
- Child:
- 1:815b206c14fb
diff -r 000000000000 -r 2bb06ba9bace Color.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Color.cpp Tue Nov 16 08:22:01 2021 +0000
@@ -0,0 +1,19 @@
+#include "Color.h"
+
+Color::Color(I2C &i2c_handle,uint8_t cmd):i2c_handle_(i2c_handle)
+{
+ const char init[]={CTRL,RESET};//初期化のコマンド
+ const char start[]={CTRL,cmd};//動作開始のコマンド
+ i2c_handle_.write(ADDR,init,2);
+ i2c_handle_.write(ADDR,start,2);
+}
+void Color::update(){
+ static const char data_pos=READ;//レジスタの読み初めの場所
+ i2c_handle_.write(ADDR,&data_pos,1);//読み込みの指定
+ i2c_handle_.read(ADDR,data_,8);//データの受信
+}
+//16bitのデータを8bitの通信で受け取るから元のデータに戻す
+uint16_t Color::r(){return data_[0]<<8|data_[1];}
+uint16_t Color::g(){return data_[2]<<8|data_[3];}
+uint16_t Color::b(){return data_[4]<<8|data_[5];}
+uint16_t Color::ir(){return data_[6]<<8|data_[7];}
\ No newline at end of file