From a3504c66276420a4c4e17d8d1898e9bfffc7b9a1 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Tue, 17 Jan 2017 17:13:02 +0100 Subject: [PATCH] Initialisierung --- Motor.cpp | 38 ++++++++++++++++++++++++++++++++++++++ Motor.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 Motor.cpp create mode 100644 Motor.h diff --git a/Motor.cpp b/Motor.cpp new file mode 100644 index 0000000..dd3b9c9 --- /dev/null +++ b/Motor.cpp @@ -0,0 +1,38 @@ +#include "Arduino.h" +#include "Motor.h" + +int Motor::getBackwardsValue(){ + if(this->forwardValue==0){ + return 1; + } + return 0; +} + +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; +} + +void Motor::forward(){ + //Motor vor Änderungen stoppen + this->stop(); + digitalWrite(this->directionPin,this->forwardValue); + analogWrite(this->pwmPin, this->speedPwm); +} + +void Motor::backward(){ + //Motor vor Änderungen stoppen + this->stop(); + digitalWrite(this->directionPin,this->getBackwardsValue()); + analogWrite(this->pwmPin, this->speedPwm); +} + +void Motor::stop(){ + digitalWrite(this->directionPin, LOW); + digitalWrite(this->pwmPin, LOW); + //Abwarten bis Rad gestoppt wurde + delay(this->directionDelay); +} diff --git a/Motor.h b/Motor.h new file mode 100644 index 0000000..4e7cc60 --- /dev/null +++ b/Motor.h @@ -0,0 +1,31 @@ +#ifndef Motor_h +#define Motor_h + +#include "Arduino.h" +/** + * Eine Klasse zur Motorsteurung unter Arduino + * @author kf + * @since 2016-01-17 + **/ +class Motor{ + private: + int pwmPin; + int directionPin; + int forwardValue; + int speedPwm; + int directionDelay; + //Liefert den Vorwärtswert;HIGH oder LOW zurück + int getBackwardsValue(); + public: + //Initialisierung der Klassenattribute + Motor(int pwmPin, int directionPin,bool forwardBool,int speedPwm,int directionDelay); + //Dreht das Rad vorwärts + void forward(); + //Dreht das Rad rückwärts + void backward(); + //Stoppt den Motor + void stop(); +}; + +#endif +