田中くんのモタドラを制御する石本さんのやつ

Revision:
8:2759e619969a
Parent:
7:a1d54597161d
diff -r a1d54597161d -r 2759e619969a T_motor.cpp
--- 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;
 }