mirror of
https://github.com/kevinveenbirkenbach/arduino_motor_controll.git
synced 2024-11-23 11:21:03 +01:00
Initialisierung
This commit is contained in:
parent
11e1c4c7b0
commit
a3504c6627
38
Motor.cpp
Normal file
38
Motor.cpp
Normal 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
31
Motor.h
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user