![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Dependencies: FastPWM GMD_template_lib mbed
main.cpp
- Committer:
- inst
- Date:
- 2016-07-03
- Revision:
- 5:9d1b1948a9b6
- Parent:
- 4:894559ccce05
- Child:
- 6:004e6174445a
File content as of revision 5:9d1b1948a9b6:
#include "mbed.h" #include "GMD.hpp" char read_address() { const size_t din_num = 4; DigitalIn din[] = { DigitalIn(dp26), DigitalIn(dp25), DigitalIn(dp18), DigitalIn(dp17) }; char address = 0; size_t address_offset = 0x08 << 1; for (size_t i = 0; i < din_num; ++i) { address |= din[i].read() << (i + 1); } return address + address_offset; } int main(){ I2CSlave i2c(dp5, dp27); i2c.address(read_address()); basic_motor_driver md(dp1, dp2, dp9); while (true){ char buf; switch (i2c.receive()){ case I2CSlave::ReadAddressed: break; case I2CSlave::WriteGeneral: break; case I2CSlave::WriteAddressed: i2c.read(&buf, 1); float p = (buf & 0x80) ? -1.0f : 1.0f; p *= (buf & 0x7F); p *= 1.0f / 0x7F; md.set(p); break; case I2CSlave::NoData: break; } } }