diff --git a/Motor.cpp b/Motor.cpp index dd3b9c9..a2e047a 100644 --- a/Motor.cpp +++ b/Motor.cpp @@ -8,26 +8,39 @@ int Motor::getBackwardsValue(){ return 0; } +int Motor::getSpeed(int direction){ + if(direction==LOW){ + return 255-this->speedPwm; + } + return this->speedPwm; +} + Motor::Motor(int pwmPin, int directionPin,bool forwardValue, int speedPwm, int directionDelay){ this->pwmPin = pwmPin; this->directionPin = directionPin; this->forwardValue = forwardValue; this->speedPwm = speedPwm; this->directionDelay= directionDelay; + + //Pins auf Output setzen + pinMode(pwmPin, OUTPUT ); + pinMode(directionPin, OUTPUT ); + digitalWrite(pwmPin, LOW ); + digitalWrite(directionPin, LOW ); } void Motor::forward(){ //Motor vor Änderungen stoppen this->stop(); digitalWrite(this->directionPin,this->forwardValue); - analogWrite(this->pwmPin, this->speedPwm); + analogWrite(this->pwmPin, this->getSpeed(this->forwardValue)); } void Motor::backward(){ //Motor vor Änderungen stoppen this->stop(); digitalWrite(this->directionPin,this->getBackwardsValue()); - analogWrite(this->pwmPin, this->speedPwm); + analogWrite(this->pwmPin, this->getSpeed(this->getBackwardsValue())); } void Motor::stop(){ diff --git a/Motor.h b/Motor.h index 4e7cc60..0f1ce5c 100644 --- a/Motor.h +++ b/Motor.h @@ -14,6 +14,10 @@ class Motor{ int forwardValue; int speedPwm; int directionDelay; + + //Liefert die PWM-Geschwindigkeit in Abhängigkeit von der Richtung zurück + int getSpeed(int direction); + //Liefert den Vorwärtswert;HIGH oder LOW zurück int getBackwardsValue(); public: