田中くんのモタドラを制御する石本さんのやつ
Revision 8:2759e619969a, committed 2017-09-27
- Comitter:
- fujikenac
- Date:
- Wed Sep 27 10:28:52 2017 +0000
- Parent:
- 7:a1d54597161d
- Commit message:
- fix i2c
Changed in this revision
T_motor.cpp | Show annotated file Show diff for this revision Revisions of this file |
T_motor.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/T_motor.cpp Thu Sep 21 08:14:35 2017 +0000 +++ b/T_motor.cpp Wed Sep 27 10:28:52 2017 +0000 @@ -9,18 +9,13 @@ void T_motor::init(char addr,int freq = 100000) { setAddr(addr); - i2c.frequency(freq); + i2c->frequency(freq); char d = 0; - i2c.write((addr+1) << 1,&d,1); + i2c->write((addr+1) << 1,&d,1); wait(0.01); } -T_motor::T_motor(PinName sda,PinName scl,int addr):i2c(sda,scl) -{ - init(addr); -} - -T_motor::T_motor(I2C& i2c_,int addr):i2c(i2c_) +T_motor::T_motor(I2C* i2c_,int addr):i2c(i2c_) { init(addr); } @@ -49,7 +44,7 @@ bool f = 0; char d = speed; - if(mode == 0 || mode == 1)f = i2c.write((addr+mode) << 1,&d,1); + if(mode == 0 || mode == 1)f = i2c->write((addr+mode) << 1,&d,1); wait(0.01); return f; }
--- a/T_motor.h Thu Sep 21 08:14:35 2017 +0000 +++ b/T_motor.h Wed Sep 27 10:28:52 2017 +0000 @@ -4,13 +4,12 @@ class T_motor { private: - I2C i2c; + I2C *i2c; char addr; public: void setAddr(int addr_); void init(char addr,int freq); - T_motor(PinName sda,PinName scl,int addr); - T_motor(I2C& i2c_,int addr); + T_motor(I2C* i2c_,int addr); T_motor& operator=(float fval); void control(float fval); bool run(char mode,char speed);