Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Motor {
- private:
- int pinvel, dir1, dir2;
- int vel;
- public:
- void setPinuot(int velocidadPin, int dirPin1, int dirPin2) {
- vel = 0;
- pinvel = velocidadPin;
- dir1 = dirPin1;
- dir2 = dirPin2;
- pinMode(pinvel, OUTPUT);
- pinMode(dir1, OUTPUT);
- pinMode(dir2, OUTPUT);
- off();
- }
- void setVelocidad(int velocidad, bool mover = true) {
- if (vel >= 0) {
- vel = velocidad;
- digitalWrite(dir1, LOW);
- digitalWrite(dir2, HIGH);
- }
- else {
- vel = -velocidad;
- digitalWrite(dir1, HIGH);
- digitalWrite(dir2, LOW);
- }
- if (mover) {
- analogWrite(pinvel, vel);
- }
- }
- void parar() {
- analogWrite(pinvel, 0);
- }
- void arrancar() {
- analogWrite(pinvel, vel);
- }
- void off() {
- vel = 0;
- digitalWrite(dir1, LOW);
- digitalWrite(dir1, LOW);
- analogWrite(pinvel, vel);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement