#include "weistra.h"const int pinA = 2 ; const int pinB = 3 ;const int Fmin = 50 ; const int Fmax = 100 ;const int CS = A0 ;const int potPin = A1 ;const int acceleration = 500 ;const int potMiddle = 512 ;const int deadRange = 20 ;Weistra pwm( pinA, pinB, Fmin, Fmax ) ;void setup(){ pinMode( potPin, INPUT ) ; pwm.begin() ; uint8_t currentLimit = 169 ; /*currentLimit = Imax * Rshunt / 0.00488 -> 2.5A x 0.33R (3x 1R parallel) / 0.00488 = 169 */ pwm.setCurrentSense( CS, currentLimit )}void loop(){ static uint32_t lastTime = 0 ; if( millis() - lastTime >= acceleration ) // run every interval time { lastTime = millis() ; static int8_t throttle = 0 ; int8_t setPoint = 0 ; int sample = analogRead( potPin ) ; if( sample <= potMiddle - deadRange ) setPoint = map( sample, 0, potMiddle - deadRange , -100, 0 ) ; // scale [0.. middle -20] to [-100..0] else if( sample >= potMiddle + deadRange ) setPoint = map( sample, potMiddle + deadRange , 1023, 0, 100 ) ; // scale [middle + 20 .. 1023] to [0..100] else setPoint = 0 ; // middle 40 adc steps = dead range -> speed 0 if( throttle < setPoint ) throttle ++ ; if( throttle > setPoint ) throttle -- ; pwm.setSpeed( throttle ) ; } pwm.update() ; // also handles short circuit.}