Skip to content

# File evamTA6586Driver.h

File List > src > evamTA6586Driver.h

Go to the documentation of this file

    #pragma once

    #include <Arduino.h>

    namespace evam
    {
        template <int kForwardPin, int kBackwardPin>
        class TA6586Driver
        {
        public:
            TA6586Driver()
            {
                pinMode(kForwardPin, OUTPUT);
                pinMode(kBackwardPin, OUTPUT);
                actBipolar(0);
            }

            int GetForwardPin() const
            {
                return kForwardPin;
            }

            int GetBackwardPin() const
            {
                return kBackwardPin;
            }

        protected:
            void actBipolar(signed short aValue)
            {
                int normalized = map(constrain(aValue, -1000, 1000), -1000, 1000, -255, 255);
                analogWrite(kForwardPin, max(0, normalized));
                analogWrite(kBackwardPin, max(0, -normalized));
            }
        };
    }