Initialisierung

This commit is contained in:
Kevin Frantz 2017-01-17 17:13:02 +01:00
parent 11e1c4c7b0
commit a3504c6627
2 changed files with 69 additions and 0 deletions

38
Motor.cpp Normal file
View File

@ -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);
}

31
Motor.h Normal file
View File

@ -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