ported to use hardware I2C
Dependents: tc_agent Line_Trace_No_collision_Light_control_longer_dis
Revision 0:61de426fb945, committed 2016-07-19
- Comitter:
- maruta
- Date:
- Tue Jul 19 03:50:10 2016 +0000
- Commit message:
- ported to use hardware I2C;
Changed in this revision
S11059.cpp | Show annotated file Show diff for this revision Revisions of this file |
S11059.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 61de426fb945 S11059.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/S11059.cpp Tue Jul 19 03:50:10 2016 +0000 @@ -0,0 +1,23 @@ +#include "S11059.h" + +S11059::S11059(PinName sda, PinName scl): _i2c(sda,scl){ + char dat[2]; + dat[0] = 0x00; + dat[1] = 0x8a; + _i2c.write(S11059_ADDR,dat,2); + dat[1] = 0x0a; + _i2c.write(S11059_ADDR,dat,2); +} + +void S11059::update(){ + uint8_t buf[8]; + char dataout[1]={0x03}; + _i2c.write(S11059_ADDR, (char *) dataout, 1); + _i2c.read(S11059_ADDR, (char *) buf,8); + r=buf[0]<<8|buf[1]; + g=buf[2]<<8|buf[3]; + b=buf[4]<<8|buf[5]; +} + +S11059::~S11059(){ +} \ No newline at end of file
diff -r 000000000000 -r 61de426fb945 S11059.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/S11059.h Tue Jul 19 03:50:10 2016 +0000 @@ -0,0 +1,18 @@ +#ifndef S11059_H_ +#define S11059_H_ + +#include "mbed.h" + +#define S11059_ADDR (0x2A<<1) + +class S11059{ +public: + S11059(PinName sda, PinName scl); + virtual ~S11059(); + int r,g,b,ir; + void update(); +private: + I2C _i2c; +}; + +#endif /* S11059_SOFTI2C_H_ */ \ No newline at end of file