Files
Pendelzug/lib/fahrt/fahrt.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

78 lines
1.9 KiB
C++

# include<Arduino.h>
#include<fahrt.h>
#include<locomotive.h>
Fahrt::Fahrt(Locomotive locomotive, MotorDirection Direction, Gleis gleis, Gleisabschnitt gleisabschnitt): _locomotive(locomotive), _gleis(gleis), _gleisabschnitt(gleisabschnitt)
{
_direction = Direction;
_speed = locomotive.getDefaultSpeed();
_bremsweg=0;
}
Fahrt::Fahrt(Locomotive locomotive, byte speed, MotorDirection Direction, Gleis gleis, Gleisabschnitt gleisabschnitt): _locomotive(locomotive), _gleis(gleis), _gleisabschnitt(gleisabschnitt)
{
_direction = Direction;
_speed = speed;
_bremsweg=0;
}
Fahrt::Fahrt(Locomotive locomotive, byte speed, MotorDirection Direction, Gleis gleis, Gleisabschnitt gleisabschnitt, float bremsweg): _locomotive(locomotive), _gleis(gleis), _gleisabschnitt(gleisabschnitt)
{
_direction = Direction;
_speed = speed;
_bremsweg=bremsweg;
}
void Fahrt::Vorbereiten()
{
_gleis.Waehlen();
_abschnittErkannt=false;
Serial.print ("Auftrag: Speed=");
Serial.print (_speed);
Serial.print (" Bremsweg=");
Serial.print (_bremsweg);
Serial.println();
}
void Fahrt::Start()
{
_locomotive.setDirection(_direction);
_locomotive.Accelerate(_speed);
}
void Fahrt::Loop()
{
_locomotive.loop();
if (_gleisabschnitt.IstBesetzt() && !_abschnittErkannt)
{
delay(20);
if (_gleisabschnitt.IstBesetzt() && !_abschnittErkannt)
{
if (_bremsweg==0)
_locomotive.Break();
else
_locomotive.Accelerate(0, _bremsweg);
_abschnittErkannt=true;
}
}
}
bool Fahrt::IstAngekommen()
{
return (_locomotive.currentSpeed()==0);
}
float Fahrt::ChangeBremsweg(float DeltaBremsweg)
{
_bremsweg += DeltaBremsweg;
return(_bremsweg);
}
byte Fahrt::ChangeSpeed(byte DeltaSpeed)
{
_speed += DeltaSpeed;
return(_speed);
}