Skip to content

# File evamTB6612Driver.h

File List > src > evamTB6612Driver.h

Go to the documentation of this file

    #pragma once
    #include <Arduino.h>
    namespace evam
    {
        template <int kPinSpeed, int kPinMode1, int kPinMode2>
        class TB6612FNGDriver
        {

        public:
            TB6612FNGDriver()
            {
                pinMode(kPinSpeed, OUTPUT);
                pinMode(kPinMode1, OUTPUT);
                pinMode(kPinMode2, OUTPUT);
                actBipolar(0);
            }

            int GetSpeedPin() const
            {
                return kPinSpeed;
            }

            int GetMode1Pin() const
            {
                return kPinMode1;
            }

            int GetMode2Pin() const
            {
                return kPinMode2;
            }

        protected:
            void actBipolar(signed short aValue)
            {
                int pwm = map(constrain(abs(aValue), 0, 1000), 0, 1000, 0, 255);
                digitalWrite(kPinMode1, aValue > 0);
                digitalWrite(kPinMode2, aValue < 0);
                analogWrite(kPinSpeed, pwm);
            }
        };
    }