Advertisement
sombruxo

motor.h

May 26th, 2023
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. class Motor {
  2. private:
  3. int pinvel, dir1, dir2;
  4. int vel;
  5.  
  6. public:
  7. void setPinuot(int velocidadPin, int dirPin1, int dirPin2) {
  8. vel = 0;
  9. pinvel = velocidadPin;
  10. dir1 = dirPin1;
  11. dir2 = dirPin2;
  12. pinMode(pinvel, OUTPUT);
  13. pinMode(dir1, OUTPUT);
  14. pinMode(dir2, OUTPUT);
  15. off();
  16. }
  17.  
  18. void setVelocidad(int velocidad, bool mover = true) {
  19. if (vel >= 0) {
  20. vel = velocidad;
  21. digitalWrite(dir1, LOW);
  22. digitalWrite(dir2, HIGH);
  23. }
  24. else {
  25. vel = -velocidad;
  26. digitalWrite(dir1, HIGH);
  27. digitalWrite(dir2, LOW);
  28. }
  29. if (mover) {
  30. analogWrite(pinvel, vel);
  31. }
  32. }
  33.  
  34. void parar() {
  35. analogWrite(pinvel, 0);
  36. }
  37.  
  38. void arrancar() {
  39. analogWrite(pinvel, vel);
  40. }
  41.  
  42. void off() {
  43. vel = 0;
  44. digitalWrite(dir1, LOW);
  45. digitalWrite(dir1, LOW);
  46. analogWrite(pinvel, vel);
  47. }
  48. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement