Library for controlling Robot via I2C.

I2CRobot.cpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Copyright (C) 2016 Wesley Tsai (wesleyboy42@gmail.com)
  3. Permission is hereby granted, free of charge, to any person obtaining a copy of
  4. this software and associated documentation files (the "Software"), to deal in
  5. the Software without restriction, including without limitation the rights to
  6. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  7. the Software, and to permit persons to whom the Software is furnished to do so,
  8. subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  13. FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  14. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  15. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. */
  18. /*
  19. * Library for controlling robot via I2C.
  20. *
  21. * Information about the makercup obtained from:
  22. * https://medium.com/maker-cup
  23. */
  24. // --------------------------------------------------------------------------------------
  25. #include "I2CRobot.h"
  26. #include <Wire.h>
  27. // --------------------------------------------------------------------------------------
  28. I2CRobot::I2CRobot(byte ID):_ID(ID)
  29. {
  30. }
  31. I2CRobot::~I2CRobot()
  32. {
  33. }
  34. // --------------------------------------------------------------------------------------
  35. void I2CRobot::init()
  36. {
  37. Wire.begin();
  38. }
  39. void I2CRobot::hello(void)
  40. {
  41. Wire.beginTransmission(_ID);
  42. Wire.write(_hello);
  43. Wire.endTransmission();
  44. }
  45. void I2CRobot::order(void)
  46. {
  47. Wire.beginTransmission(_ID);
  48. Wire.write(_order);
  49. Wire.endTransmission();
  50. }
  51. void I2CRobot::check(void)
  52. {
  53. Wire.beginTransmission(_ID);
  54. Wire.write(_check);
  55. Wire.endTransmission();
  56. }
  57. void I2CRobot::custom(byte custom)
  58. {
  59. Wire.beginTransmission(_ID);
  60. Wire.write(custom);
  61. Wire.endTransmission();
  62. }