From a5f5b18a279c1847b8b541115b3a7a232203026c Mon Sep 17 00:00:00 2001 From: Andi Date: Thu, 18 May 2023 23:12:14 +0200 Subject: [PATCH] =?UTF-8?q?Umstellung=20der=20Abbremsung=20auf=20durchg?= =?UTF-8?q?=C3=A4ngig=20float?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/locomotive/locomotive.cpp | 6 +++--- lib/locomotive/locomotive.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/locomotive/locomotive.cpp b/lib/locomotive/locomotive.cpp index 83c90e4..8bf9291 100644 --- a/lib/locomotive/locomotive.cpp +++ b/lib/locomotive/locomotive.cpp @@ -60,7 +60,7 @@ void Locomotive::Break() void Locomotive::setSpeed(byte Speed) { _currentSpeed = Speed; - _motor.setSpeed(_currentSpeed); + _motor.setSpeed( (int) (_currentSpeed+0.5)); }; void Locomotive::setDirection(MotorDirection dir) @@ -76,7 +76,7 @@ void Locomotive::loop() currentMillis = millis(); if (currentMillis - _millisStart >= _delay) //test whether the period has elapsed { - byte newspeed; + float newspeed; newspeed = _currentSpeed + _currentAcc; /* Serial.print("Locomotive.Loop: "); Serial.print(_currentSpeed); @@ -109,7 +109,7 @@ void Locomotive::loop() byte Locomotive::currentSpeed() { - return _currentSpeed; + return ((byte) (_currentSpeed+0.5)); }; byte Locomotive::getDefaultSpeed() diff --git a/lib/locomotive/locomotive.h b/lib/locomotive/locomotive.h index 1ccf140..e7d0220 100644 --- a/lib/locomotive/locomotive.h +++ b/lib/locomotive/locomotive.h @@ -22,13 +22,13 @@ class Locomotive private: int _accelerate; int _decelerate; - int _currentAcc; + float _currentAcc; byte _minSpeed; byte _maxSpeed; byte _targetSpeed; const unsigned int _delay=300; unsigned long _millisStart; - byte _currentSpeed; + float _currentSpeed; IMotor& _motor; };