#include <Wire.h> // Wire Bibliothek hochladen
#include <LiquidCrystal_I2C.h> // Vorher hinzugefügte LiquidCrystal_I2C Bibliothek hochladen
LiquidCrystal_I2C lcd(0x3F,20,4); // Hier wird festgelegt um was für einen Display es sich handelt. Arduino Uno: I2C pins sind A4==SDA, A5==SCL
int taste = A0; // Variablen für Reglerwahl mit Taste
int taste2 = A1;
int tastestatus;
int tastestatus2;
int letzterstatus;
int tastezaehler = 0;
int shiftPin = 5; // Pin verbunden mit SRCLK des 74HC595
int storePin = 6; // Pin verbunden mit RCLK des 74HC595
int dataPin = 7; // Pin verbunden mit SER des 74HC595
long geschwindigkeit1 = 8; // Variablen für Geschwindigkeitsanzeige
long geschwindigkeit2 = 9;
long geschwindigkeit3 = 10;
long datenwort; // Variablen für Datenworte
long autopacecar;
long Reglerdatenwort1;
long Reglerdatenwort2;
long Reglerdatenwort3;
long Reglerdatenwort4;
long Reglerdatenwort5;
long Reglerdatenwort6;
long fahrer1; // Fahrer 1-6
long fahrer2;
long fahrer3;
long fahrer4;
long fahrer5;
long fahrer6;
// 0 1 2 3 4 5 6 7 8 9
byte zahl[10] = {0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110, 0b01101101, 0b01111101, 0b00000111, 0b01111111, 0b01101111};
byte zehner[10] = {0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110, 0b01101101, 0b01111101, 0b00000111, 0b01111111, 0b01101111};
byte Position[9] ={0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110, 0b01101101, 0b01111101, 0b00000111, 0b01111111};
byte DIG_zehner = 0b10000000; // Zehnerstelle aus (zweistellige 7-Segmentanzeige)
int k = 0; // Hochzähler f. Positionsanzeige
int j = 0; // Hochzähler f. Rundenanzeige Zehnerstelle
int i = 0; // Hochzähler f. Rundenanzeige Einerstelle
int runde; // Rundenzähler (d. Führenden)
int rundefahrer; // Rundenzähler des Fahrers
int rundedif; // Rundendifferenz zum Führenden
long rundenzeit = 0; // alte Rundenzeit
float rundenzeitfahrer = 0; // Ermittelte Rundenzeit des Fahrers
float rundenzeitfahrer2 = 0; // Zwischenspeicher Rundenzeit des Fahrers
float bestzeitfahrer = 0; // Bestzeit
int mindestrundenzeit = 2000; // Mindestrundenzeit
boolean fahrerbest;
boolean fahrerzeit;
unsigned long zeit = 0; // Variable um den aktuellen Timestamp zu speichern
int tank1 = 11; // Tank-LED
int tank2 = 12; // Tank-LED
int tank3 = 13; // Tank-LED
int intervall = 500; // Blinkintervall f. Tankreserve
unsigned long previousMillis = 0; // Variable f. Timestamp v. Tankreserve-blinken
unsigned long lcdzeitfenster = 0; // Variable f. Timestamp v. LCD
int lcdzeitintervall = 300; // Zeit nach Zieldurchfahrt f. LCD
int tankstatus = LOW; // Variable um den aktuellen Status der Tank-LED zwischen zu speichern
int tankstatus2 = HIGH;
const int dataPin1 = 2; // the number of the pin to read carrera racetrack data
short wordCount = 0; // counter
volatile boolean wordChange = false; // indicates a new word is ready for further analysing
long currentWord = 0; // assemble Bits to complete data words, used in interrupt routine
volatile long Word = 0; // save data word for further computing, used in main loop and interrupt
long Words[11]; // store 10 datawords in array with counts 1..10
unsigned long intervalMicros = 0; // will store the time between two bit changes (microseconds)
unsigned long previousMicros = 0; // will store last time state when data signal has changed (microseconds)
unsigned long currentMicros = 0; // will store the current runtime (microseconds)
void setup() {
pinMode(geschwindigkeit1, OUTPUT);
pinMode(geschwindigkeit2, OUTPUT);
pinMode(geschwindigkeit3, OUTPUT);
pinMode(storePin, OUTPUT); // Pins 5,6,7 vom Schieberegister
pinMode(shiftPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(tank1, OUTPUT);
pinMode(tank2, OUTPUT);
pinMode(tank3, OUTPUT);
digitalWrite(tank1, HIGH);
digitalWrite(tank2, HIGH);
digitalWrite(tank3, HIGH);
// Serial.begin(115200); // initialize serial bus
pinMode(dataPin1, INPUT); // initialize the dataPin as an input
attachInterrupt(0, manchesterDecode, CHANGE); // whenever levels on dataPin change, start interrupt routine
pinMode(taste,INPUT);
pinMode(taste2,INPUT);
letzterstatus=digitalRead(taste);
lcd.init(); // Initialisierung LCD
lcd.backlight();
lcd.setCursor(1,0);
lcd.print("Driver Display 2.0");
lcd.setCursor(0,1);
lcd.print("<------------------>");
lcd.setCursor(1,3);
lcd.print("Fahrerauswahl: 1-6");
}
/////////////////////////////////////////////////////////////////
void Regler1(){
//Geschwindigkeitsanzeige Regler 1
if (Reglerdatenwort1>=548) {digitalWrite(geschwindigkeit1, HIGH);}
else if (Reglerdatenwort1<=547) {digitalWrite(geschwindigkeit1, LOW);}
if (Reglerdatenwort1>=558) {digitalWrite(geschwindigkeit2, HIGH);}
else if (Reglerdatenwort1<=557) {digitalWrite(geschwindigkeit2, LOW);}
if (Reglerdatenwort1>=568) {digitalWrite(geschwindigkeit3, HIGH);}
else if (Reglerdatenwort1<=567) {digitalWrite(geschwindigkeit3, LOW);}
//Positionsanzeige Regler 1
switch (fahrer1){
case 6240: k=1; break;
case 5216: k=2; break;
case 7264: k=3; break;
case 4704: k=4; break;
case 6752: k=5; break;
case 5728: k=6; break;
case 7776: k=7; break;
case 4448: k=8; break;
}
//Tankanzeige Regler 1
switch (fahrer1){
case 4176: digitalWrite(tank1, HIGH); digitalWrite(tank2, LOW); // Wenn Tank leer Reserve-LED leuchtet
digitalWrite(tank3, LOW); tankstatus2 = HIGH;
break;
case 6224: digitalWrite(tank1, tankstatus); digitalWrite(tank2, LOW); // Wenn Tank auf 1/7 Reserve-LED blinkt (s. Loop)
digitalWrite(tank3, LOW); tankstatus2 = LOW;
break;
case 4688: digitalWrite(tank1, HIGH); digitalWrite(tank2, HIGH); // Wenn Tank auf 4/7, die 3. LED aus
digitalWrite(tank3, LOW); tankstatus2 = HIGH;
break;
case 7760: digitalWrite(tank1, HIGH); digitalWrite(tank2, HIGH); // Wenn Tank voll, alle 3 LEDs an
digitalWrite(tank3, HIGH); tankstatus2 = HIGH;
break;
}