/*
Project Cars Arduino Dashboard Ver: 1.3.2 one TM1638 mdule
Support: http://forum.projectcarsgame.com/showthread.php?29762-Arduino-Dashboard
Dokumentation: http://www.ws-clan.de/pc_dash/Readme.pdf
Software: http://www.ws-clan.de/pc_dash/index.php
copyright 2015 saibot852 http://forum.projectcarsgame.com/member.php?105167-saibot852
*/
#include <TM1638.h>
#include <stdio.h>
#include <string.h>
// define a module on data pin 8, clock pin 9 and strobe pin 7
TM1638 module(8, 9, 7);
int vRpm, vGear, vDisplay, vSpeed, vTemp = 0, vAbs = 0, vFuel = 0, vEngineState = 0;
int LEDSTATE = 0;
char incomingByte = 0;
char data[50];
String sSpeed;
String sRpm;
int Time;
String fTime;
int counter = 0;
int ledout_temp = 0;
int ledout_fuel = 0;
int ledout_engine = 0;
int ledout_indicator = 0;
int button = 1;
int state;
boolean Leds_up;
word state_leds = 0;
word leds [10] = {0, 1, 3, 7, 15, 31, 8223, 24607, 57375, 65535};
int minuten;
int sekunden;
int millisek;
int minuten5;
int sekunden5;
int millisek5;
int Time5;
String fTime5;
#include <AH_74HC595.h>
#define SER_Pin 4 //Serial data input
#define RCLK_Pin 3 //Register clock
#define SRCLK_Pin 2 //Shift register clock
AH_74HC595 seven_segment(SER_Pin, RCLK_Pin, SRCLK_Pin);
const int ledPin = 10;
const int ledPine = 11;
const int ledPinf = 6;// the number of the LED pin
// Variables will change:
int ledState = LOW;
int ledStatef = LOW;
int ledStatee = LOW;
int ledStatei = 0x0000; // ledState used to set the LED
long previousMillis = 0;
long previousMillise = 0;
long previousMillisf = 0;
long PreviousMillisi = 0;
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 500;
long intervali = 30;
String ver;
void setup() {
pinMode(6, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
ver = "1.3.2;1;";
pinMode(ledPin, OUTPUT);
Serial.begin(38400);
}
void loop() {
unsigned long CurrentMillisi = millis();
if (Serial.available() > 0) {
incomingByte = Serial.read();
if (incomingByte != ';') {
data[counter] = incomingByte;
data[counter + 1] = '\0';
counter ++;
} else {
String stringOne = data;
//version check
if (stringOne.substring(0, 3) == "VER") {
Serial.println(ver);
digitalWrite(12, HIGH);
delay(100);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
delay(100);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
delay(100);
digitalWrite(10, LOW);
digitalWrite(6, HIGH);
delay(100);
digitalWrite(6, LOW);
delay(100);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(6, HIGH);
seven_segment.showNumber(8);
module.setLEDs(0xFFFF);
module.setDisplayToString("88888888");
delay(1000);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(6, LOW);
seven_segment.clear();
module.setLEDs(0x0000);
module.clearDisplay();
//buttons send
} else if (stringOne.substring(0, 5) == "state") {
state = stringOne.substring(5, 6).toInt();
if (state == 1 ) {
if (module.getButtons() == 0b00000001) {
button = 1;
} else if (module.getButtons() == 0b00000010) {
button = 2;
} else if (module.getButtons() == 0b00000100) {
button = 3;
} else if (module.getButtons() == 0b00001000) {
button = 4;
} else if (module.getButtons() == 0b00010000) {
button = 5;
} else if (module.getButtons() == 0b00100000) {
button = 6;
} else if (module.getButtons() == 0b01000000) {
button = 7;
} else if (module.getButtons() == 0b10000000) {
button = 8;
}
String button_s = String(button);
Serial.println(button_s + ":0:0:");
}
//rpm,pos,lap right module1
} else if (stringOne.substring(0, 2) == "CC") {
sRpm = stringOne.substring(2, 6);
module.setDisplayToString(sRpm, 0, 4);
//Fuel setup display
} else if (stringOne.substring(0, 2) == "CH") {
String fuel_level = stringOne.substring(2, 6);
int fuel_level_int = stringOne.substring(2, 6).toInt();
if (fuel_level_int < 10) {
module.setDisplayToString(" 0" + fuel_level, 0b00100000, 4);
} else if (fuel_level_int < 100) {
module.setDisplayToString(" " + fuel_level, 0b00100000, 4);
} else if (fuel_level_int < 1000) {
module.setDisplayToString(" " + fuel_level, 0b00100000, 4);
} else {
module.setDisplayToString(fuel_level, 0b00100000, 4);
}
//speed left module1
} else if (stringOne.substring(0, 2) == "DD") {
sSpeed = stringOne.substring(2, 6);
module.setDisplayToString(sSpeed, 0, 0);
//time right modul 1
} else if (stringOne.substring(0, 2) == "CA") {
fTime = stringOne.substring(2, 7);
if (fTime == "0" || fTime == "-1") {
module.setDisplayToString("----", 0, 4);
} else {
int tleng = fTime.length() - 1;
int cTime = fTime.substring(0, tleng).toInt();
int mspos = tleng + 1;
millisek = fTime.substring(tleng, mspos).toInt();
minuten = (cTime % 3600) / 60;
sekunden = cTime % 60;
String min = String(minuten);
String sek = String(sekunden);
String ms = String(millisek);
if (cTime < 600) {
if (sekunden < 10) {
module.setDisplayToString(min + "0" + sek + ms, 0b10100000, 4);
} else {
module.setDisplayToString(min + sek + ms, 0b10100000, 4);
}
} else {
if (sekunden < 10) {
module.setDisplayToString(min + "0" + sek, 0b01000000, 4);
} else {
module.setDisplayToString(min + sek, 0b01000000, 4);
}
}
}
//split time right modul 1
} else if (stringOne.substring(0, 2) == "CE") {
fTime5 = stringOne.substring(2);
int tleng5 = fTime5.length() - 3;
if (tleng5 < 0) {
tleng5 = 0;
}
int cTime5 = fTime5.substring(0, tleng5).toInt();
int mspos5 = tleng5 + 3;
millisek5 = fTime5.substring(tleng5, mspos5).toInt();
minuten5 = (cTime5 % 3600) / 60;
sekunden5 = cTime5 % 60;
String min5 = String(minuten5);
String sek5 = String(sekunden5);
String ms5 = String(millisek5);
String ms5ausgabe;
if (millisek5 < 10 ) {
ms5ausgabe = "00" + ms5;
} else if (millisek5 < 100 ) {
ms5ausgabe = "0" + ms5;
} else {
ms5ausgabe = ms5;
}
if (fTime5 == "-1000" || fTime5 == "0") {
module.setDisplayToString("----", 0, 4);
} else if (cTime5 < 60) {
if (sekunden5 < 1) {
module.setDisplayToString("0" + ms5ausgabe, 0b10000000, 4);
} else if (sekunden5 < 10) {
module.setDisplayToString(sek5 + ms5ausgabe, 0b10000000, 4);
} else {
ms5ausgabe = ms5ausgabe.substring(0, 2);
module.setDisplayToString(sek5 + ms5ausgabe, 0b01000000, 4);
}
} else if (cTime5 < 600) {
if (sekunden5 < 10) {
ms5ausgabe = ms5ausgabe.substring(0, 1);
module.setDisplayToString(min5 + "0" + sek5 + ms5ausgabe, 0b10100000, 4);
} else {
ms5ausgabe = ms5ausgabe.substring(0, 1);
module.setDisplayToString(min5 + sek5 + ms5ausgabe, 0b10100000, 4);
}
} else {