Dependencies: FastPWM GMD_template_lib mbed
Revision 7:9671d3ae163e, committed 2016-07-13
- Comitter:
- inst
- Date:
- Wed Jul 13 09:02:41 2016 +0000
- Parent:
- 6:004e6174445a
- Child:
- 8:ad41522dde78
- Commit message:
- ????????????????
Changed in this revision
GMD.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/GMD.lib Sun Jul 10 13:17:14 2016 +0000 +++ b/GMD.lib Wed Jul 13 09:02:41 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/inst/code/GMD_template_lib/#6cf1d5d38ea3 +https://developer.mbed.org/users/inst/code/GMD_template_lib/#aa4eca6acb60
--- a/main.cpp Sun Jul 10 13:17:14 2016 +0000 +++ b/main.cpp Wed Jul 13 09:02:41 2016 +0000 @@ -19,32 +19,36 @@ } int main(){ + const float timeout_ms = 300; I2CSlave i2c(dp5, dp27); + Timer timer; i2c.address(read_address()); basic_motor_driver md(dp1, dp2, dp9); + timer.start(); + while (true){ char buf; switch (i2c.receive()){ case I2CSlave::ReadAddressed: + timer.reset(); break; case I2CSlave::WriteGeneral: + timer.reset(); break; case I2CSlave::WriteAddressed: + timer.reset(); i2c.read(&buf, 1); - - /* - float p = (buf & 0x80) ? -1.0f : 1.0f; - p *= (buf & 0x7F); - p *= 1.0f / 0x7F; - */ - md.set(static_cast<int8_t>(buf) / 127.0f); break; case I2CSlave::NoData: + if (timer.read_ms() > timeout_ms) { + // I2Cの通信がタイムアウトしたならブレーキ + md.release(); + } break; } }