BrickUp API Service for Docker version.

FR_DCMotor.cpp 765B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "FR_DCMotor.h"
  2. FR_DCMotor::FR_DCMotor(byte pinF,byte pinR)
  3. {
  4. _pinF=pinF;
  5. _pinR=pinR;
  6. init();
  7. }
  8. void FR_DCMotor::init()
  9. {
  10. pinMode(_pinF,OUTPUT);
  11. pinMode(_pinR,OUTPUT);
  12. }
  13. void FR_DCMotor::rotate(char dir, byte speed)
  14. {
  15. if(dir=='f' || dir=='F')
  16. {
  17. analogWrite(_pinR,0);
  18. for(int i=speed/4;i<=speed;i++)
  19. analogWrite(_pinF,i);
  20. }
  21. else if(dir=='r' || dir=='R')
  22. {
  23. analogWrite(_pinF,0);
  24. for(int i=speed/4;i<=speed;i++)
  25. analogWrite(_pinR,i);
  26. }
  27. else if(dir=='s' || dir=='S')
  28. {
  29. analogWrite(_pinF,0);
  30. analogWrite(_pinR,0);
  31. }
  32. }
  33. void FR_DCMotor::rotate(char dir)
  34. {
  35. if(dir=='s' || dir=='S')
  36. {
  37. analogWrite(_pinF,0);
  38. analogWrite(_pinR,0);
  39. }
  40. }