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
This commit is contained in:
139
src/main.cpp
Normal file
139
src/main.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
#include <Arduino.h>
|
||||
#include <dfquad.h>
|
||||
#include <motor.h>
|
||||
#include <locomotive.h>
|
||||
#include <gleis.h>
|
||||
#include <fahrt.h>
|
||||
#include <weiche.h>
|
||||
#include <L298n.h>
|
||||
#include <AnalogFiveButtons.h>
|
||||
#include <Wire.h> // Wire Bibliothek einbinden
|
||||
#include <LiquidCrystal_I2C.h> // Vorher hinzugefügte LiquidCrystal_I2C Bibliothek einbinden
|
||||
|
||||
L298n regler1(6,8,7);
|
||||
L298n regler2(5,3,4);
|
||||
|
||||
|
||||
Weiche weicheBahnhof1(regler2);
|
||||
Gleis gleis1(weicheBahnhof1, &Weiche::Geradeaus);
|
||||
Gleis gleis2(weicheBahnhof1, &Weiche::Abzweigen);
|
||||
|
||||
Gleisabschnitt bahnhof1(9);
|
||||
Gleisabschnitt bahnhof2(10);
|
||||
|
||||
/*
|
||||
Locomotive locomotiveTaurus(5, 22, 116, 180, regler1);
|
||||
Locomotive locomotive2043(6, 25, 129, 160, regler1);
|
||||
*/
|
||||
Locomotive locomotiveTaurus(5, 22, 58, 120, regler1);
|
||||
Locomotive locomotive2043(6, 25, 70, 160, regler1);
|
||||
|
||||
Fahrt fahrt[] = {
|
||||
Fahrt(locomotiveTaurus, 135, motorForward, gleis1, bahnhof2, 6.7),
|
||||
Fahrt(locomotiveTaurus, 125, motorBackward, gleis1, bahnhof1, 5.6) ,
|
||||
Fahrt(locomotive2043, 145, motorForward, gleis2, bahnhof2, 5.7),
|
||||
Fahrt(locomotive2043, 148, motorBackward, gleis2, bahnhof1, 5.3)
|
||||
};
|
||||
|
||||
int _currentFahrt;
|
||||
|
||||
LiquidCrystal_I2C lcd(0x27, 16, 2); //Hier wird festgelegt um was für einen Display es sich handelt. In diesem Fall eines mit 16 Zeichen in 2 Zeilen und der HEX-Adresse 0x27. Für ein vierzeiliges I2C-LCD verwendet man den Code "LiquidCrystal_I2C lcd(0x27, 20, 4)"
|
||||
|
||||
void initDisplay()
|
||||
{
|
||||
lcd.setCursor(0, 0);//Hier wird die Position des ersten Zeichens festgelegt. In diesem Fall bedeutet (0,0) das erste Zeichen in der ersten Zeile.
|
||||
lcd.print("Pendelzug n");
|
||||
lcd.setCursor(0, 1);// In diesem Fall bedeutet (0,1) das erste Zeichen in der zweiten Zeile.
|
||||
lcd.print("v=000 s.br=00.00");
|
||||
}
|
||||
|
||||
void dispFahrt(byte iFahrt)
|
||||
{
|
||||
lcd.setCursor(10, 0);// In diesem Fall bedeutet (0,1) das erste Zeichen in der zweiten Zeile.
|
||||
lcd.print(iFahrt);
|
||||
}
|
||||
|
||||
void dispSpeed(byte speed)
|
||||
{
|
||||
lcd.setCursor(2, 1);// In diesem Fall bedeutet (0,1) das erste Zeichen in der zweiten Zeile.
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(2, 1);// In diesem Fall bedeutet (0,1) das erste Zeichen in der zweiten Zeile.
|
||||
lcd.print(speed);
|
||||
}
|
||||
|
||||
void dispBremsweg(float bremsweg)
|
||||
{
|
||||
lcd.setCursor(11, 1);// In diesem Fall bedeutet (0,1) das erste Zeichen in der zweiten Zeile.
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(11, 1);// In diesem Fall bedeutet (0,1) das erste Zeichen in der zweiten Zeile.
|
||||
lcd.print(bremsweg);
|
||||
}
|
||||
|
||||
AnalogFiveButtonsDebounce a0button(A0, 15, 0, 31, 87, 165, 351);
|
||||
|
||||
void CheckDeltaKeys(Fahrt& fahrt)
|
||||
{
|
||||
byte key = a0button.changedButton();
|
||||
/* Serial.print("Sensor: ");
|
||||
Serial.println(sensorValue); */
|
||||
|
||||
switch(key) {
|
||||
case BTN_SELECT: {
|
||||
|
||||
break;
|
||||
}
|
||||
case BTN_LEFT: {
|
||||
Serial.println("ChangeBremsweg DOWN");
|
||||
dispBremsweg( fahrt.ChangeBremsweg(-0.3) );
|
||||
break;
|
||||
}
|
||||
case BTN_RIGHT: {
|
||||
Serial.println("ChangeBremsweg UP");
|
||||
dispBremsweg( fahrt.ChangeBremsweg( 0.3) );
|
||||
break;
|
||||
}
|
||||
case BTN_UP: {
|
||||
Serial.println("ChangeSpeed UP");
|
||||
dispSpeed( fahrt.ChangeSpeed( 5) );
|
||||
break;
|
||||
}
|
||||
case BTN_DOWN: {
|
||||
Serial.println("ChangeSpeed DOWN");
|
||||
dispSpeed( fahrt.ChangeSpeed(-5) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
_currentFahrt=3;
|
||||
Serial.begin(115200);
|
||||
lcd.init(); //Im Setup wird der LCD gestartet
|
||||
lcd.backlight(); //Hintergrundbeleuchtung einschalten (lcd.noBacklight(); schaltet die Beleuchtung aus).
|
||||
initDisplay();
|
||||
};
|
||||
|
||||
void loop() {
|
||||
|
||||
// put your main code here, to run repeatedly:
|
||||
if (fahrt[_currentFahrt].IstAngekommen())
|
||||
{
|
||||
delay(2000);
|
||||
|
||||
Serial.println("Andere Fahrt");
|
||||
_currentFahrt = (_currentFahrt + 1) % 4;
|
||||
fahrt[_currentFahrt].Vorbereiten();
|
||||
|
||||
dispFahrt(_currentFahrt+1);
|
||||
dispSpeed( fahrt[_currentFahrt].ChangeSpeed(0) );
|
||||
dispBremsweg( fahrt[_currentFahrt].ChangeBremsweg( 0.0) );
|
||||
|
||||
delay(1000);
|
||||
|
||||
fahrt[_currentFahrt].Start();
|
||||
}
|
||||
CheckDeltaKeys(fahrt[_currentFahrt]);
|
||||
fahrt[_currentFahrt].Loop();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user