Files
Pendelzug/lib/L298n/L298n.cpp
Andi 349d1d644e Pendelzug Erstversion
new file:   .gitignore
new file:   .vscode/extensions.json
new file:   ErsterTest.code-workspace
new file:   include/README
new file:   lib/AnalogFiveButtons/AnalogFiveButtons.cpp
new file:   lib/AnalogFiveButtons/AnalogFiveButtons.h
new file:   lib/Imotor/Imotor.cpp
new file:   lib/Imotor/Imotor.h
new file:   lib/L298n/L298n.cpp
new file:   lib/L298n/L298n.h
new file:   lib/README
new file:   lib/fahrt/fahrt.cpp
new file:   lib/fahrt/fahrt.h
new file:   lib/gleis/gleis.cpp
new file:   lib/gleis/gleis.h
new file:   lib/gleisabschnitt/gleisabschnitt.cpp
new file:   lib/gleisabschnitt/gleisabschnitt.h
new file:   lib/locomotive/locomotive.cpp
new file:   lib/locomotive/locomotive.h
new file:   lib/motor/dfquad.h
new file:   lib/motor/motor.cpp
new file:   lib/motor/motor.h
new file:   lib/weiche/weiche.cpp
new file:   lib/weiche/weiche.h
new file:   platformio.ini
new file:   src/main.cpp
new file:   test/README
2023-05-14 21:22:04 +02:00

62 lines
1.6 KiB
C++

#include "IMotor.h"
#include <L298n.h>
#include "Arduino.h"
L298n::L298n(int pinPwm, int pin1, int pin2)
{
_pinPwm = pinPwm;
_pin1 = pin1;
_pin2 = pin2;
_currentDir = motorForward;
pinMode(_pinPwm,OUTPUT);
pinMode(_pin1,OUTPUT);
pinMode(_pin2,OUTPUT);
digitalWrite(_pin1, LOW);
digitalWrite(_pin2, LOW);
}
void L298n::setSpeed(int speed)
{
/* Serial.print("Regler Speed:" );
Serial.print(speed);
Serial.print(" on ");
Serial.println(_pinPwm); */
analogWrite(_pinPwm, speed);
setDirection(_currentDir);
}
void L298n::setDirection(MotorDirection dir)
{
_currentDir=dir;
if (_currentDir == motorBackward)
{
/* Serial.print("Regler backward");
Serial.print(_pin1);
Serial.print("-");
Serial.println(_pin2); */
digitalWrite(_pin2, LOW);
digitalWrite(_pin1, HIGH);
}
else
{
/* Serial.print("Regler forward");
Serial.print(_pin1);
Serial.print("-");
Serial.println(_pin2); */
digitalWrite(_pin1, LOW);
digitalWrite(_pin2, HIGH);
}
}
void L298n::Stop()
{
digitalWrite(_pin1, LOW);
digitalWrite(_pin2, LOW);
setSpeed (0);
}