Skip to content
Snippets Groups Projects
Commit bb874760 authored by Orhan-Timo Altan's avatar Orhan-Timo Altan
Browse files

Kleine Änderungen und neue Funktion hinzugefügt (drive)

parent bce2e75b
Branches
No related tags found
No related merge requests found
......@@ -31,75 +31,64 @@ DCMotor::DCMotor(const String& NAME, uint8_t MOTOR_COUNT, uint8_t PIN_STBY, uint
}
}
void DCMotor::forward(uint16_t VEL)
void DCMotor::forward(byte vel)
{
if (NAME == "TB6612FNG")
{
if (MOTOR_COUNT == 1)
{
digitalWrite(PIN_STBY, HIGH);
analogWrite(PIN_PWM1, VEL);
analogWrite(PIN_PWM1, vel);
digitalWrite(PIN_IN1, LOW);
digitalWrite(PIN_IN2, HIGH);
}
if (MOTOR_COUNT == 2)
{
digitalWrite(PIN_STBY, HIGH);
analogWrite(PIN_PWM1, VEL);
analogWrite(PIN_PWM1, vel);
digitalWrite(PIN_IN1, LOW);
digitalWrite(PIN_IN2, HIGH);
analogWrite(PIN_PWM2, VEL);
analogWrite(PIN_PWM2, vel);
digitalWrite(PIN_IN3, LOW);
digitalWrite(PIN_IN4, HIGH);
}
}
}
void DCMotor::backward(uint16_t VEL){
void DCMotor::backward(byte vel){
if (NAME == "TB6612FNG")
{
if (MOTOR_COUNT == 1)
{
digitalWrite(PIN_STBY, HIGH);
analogWrite(PIN_PWM1, VEL);
analogWrite(PIN_PWM1, vel);
digitalWrite(PIN_IN1, HIGH);
digitalWrite(PIN_IN2, LOW);
}
if (MOTOR_COUNT == 2)
{
digitalWrite(PIN_STBY, HIGH);
analogWrite(PIN_PWM1, VEL);
analogWrite(PIN_PWM1, vel);
digitalWrite(PIN_IN1, HIGH);
digitalWrite(PIN_IN2, LOW);
analogWrite(PIN_PWM2, VEL);
analogWrite(PIN_PWM2, vel);
digitalWrite(PIN_IN3, HIGH);
digitalWrite(PIN_IN4, LOW);
}
}
}
// void DCMotor::drive(int16_t VEL){
// if (NAME == "TB6612FNG")
// {
// if (MOTOR_COUNT == 1)
// {
// digitalWrite(PIN_STBY, HIGH);
// analogWrite(PIN_PWM1, VEL);
// digitalWrite(PIN_IN1, HIGH);
// digitalWrite(PIN_IN2, LOW);
// }
// if (MOTOR_COUNT == 2)
// {
// digitalWrite(PIN_STBY, HIGH);
// analogWrite(PIN_PWM1, VEL);
// digitalWrite(PIN_IN1, HIGH);
// digitalWrite(PIN_IN2, LOW);
// analogWrite(PIN_PWM2, VEL);
// digitalWrite(PIN_IN3, HIGH);
// digitalWrite(PIN_IN4, LOW);
// }
// }
// }
void DCMotor::drive(int direction, byte vel){
if (NAME == "TB6612FNG")
{
if (direction < 0){
DCMotor::backward(vel);
}
else {
DCMotor::forward(vel);
}
}
}
void DCMotor::stop(){
if (NAME == "TB6612FNG")
......
/*
* Klasse: DCM
* Klasse: DCMotor
*
* Zur ansteuerung von Gleichstrommotoren mit verschiedenen Motortreibern
*
......@@ -7,8 +7,8 @@
*
*/
#ifndef DCM_H
#define DCM_H
#ifndef BITSDCM_H
#define BITSDCM_H
#include <Arduino.h>
......@@ -16,15 +16,16 @@ class DCMotor
{
public:
DCMotor(const String& NAME, const uint8_t MOTOR_COUNT, const uint8_t PIN_STBY, const uint8_t PIN_PWM1, const uint8_t PIN_IN1, const uint8_t PIN_IN2, const uint8_t PIN_PWM2 = 0, const uint8_t PIN_IN3 = 0, const uint8_t PIN_IN4 = 0);
void forward(uint16_t VEL);
void backward(uint16_t VEL);
void drive(int16_t t_VEL);
void forward(byte vel);
void backward(byte vel);
void drive(int16_t direction, byte vel);
void stop();
private:
const String& NAME;
uint8_t MOTOR_COUNT, PIN_STBY, PIN_PWM1, PIN_IN1, PIN_IN2, PIN_PWM2, PIN_IN3, PIN_IN4;
uint16_t VEL;
int16_t direction;
byte vel;
};
#endif
\ No newline at end of file
# **DC-Motor**
# **BITs DCMotor**
Eine Klasse zur Ansteuerung von Gleichstrommotoren für unterschiedliche Motortreiber.
......@@ -22,7 +22,7 @@ Es wird für jeden Motortreiber nur ein Objekt benötigt, der beim instanziieren
Einbinden der Libraries:
`#include <DCM.h>`<br />
`#include <DCMotor.h>`<br />
<br />
Instanziieren eines Motortreiber-Objektes:
......
......@@ -6,7 +6,7 @@ const int Motor_IN1 = 40;
const int Motor_IN2 = 42;
const int Motor_Count = 1;
const String Motor_driver_name = "TB6612FNG";
int velocity = 150;
byte velocity = 150;
DCMotor Motor(Motor_driver_name, Motor_Count, Motor_STBY, Motor_PWM, Motor_IN1, Motor_IN2);
......@@ -28,4 +28,16 @@ void loop()
Motor.stop();
delay(1000);
Motor.drive(1, velocity); // Vorwärts
delay(2000);
Motor.stop();
delay(1000);
Motor.drive(-1, velocity); // Rückwärts
delay(2000);
Motor.stop();
delay(1000);
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
# Datatypes (KEYWORD1)
#######################################
DCM KEYWORD1
DCMotor KEYWORD1
#######################################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment