/*
Supra Uhrersatzanzeige
Funktionen:
Uhr - ok
Wassertemp - ok
Öltemp - ok
AFR - ok
Öldruck - ok
Ladedruck - ok
Vorwärtstaste - ok
Rückwärtstaste - ok
Uhrzeittaste - ok
Warnbuzzer - ok
*/
#include "RTClib.h"
#include "U8glib.h"
#define NXT_SCRN_BUTTON 4 //Pin Digitaleingang für Schalter nächster Bildschirm
#define PRVS_SCRN_BUTTON 3 //Pin Digitaleingang für Schalter vorheriger Bildschirm
#define HOME_SCRN_BUTTON 5 //Pin Digitaleingang für Schalter Uhrzeit Bildschirm
#define WARNTON 6 //Pin Digitalausgang für Warnton zum Ansprechen des Buzzers
#define NOTE_C5 523 //Tone für Wannbuzzer
RTC_DS1307 rtc;
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI
//Bild zu code: https://javl.github.io/image2cpp/
// 'supra_logo', 128x32px
const unsigned char boot_supra_logo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0xfc, 0x03, 0xe0, 0x07, 0xc3, 0xff, 0xfe, 0x07, 0xff, 0xfc, 0x00, 0x3f, 0xfc, 0x00,
0x01, 0x80, 0x03, 0x02, 0x20, 0x04, 0x42, 0x00, 0x01, 0x84, 0x00, 0x03, 0x00, 0xc0, 0x03, 0x00,
0x02, 0x00, 0x00, 0x82, 0x20, 0x04, 0x42, 0x00, 0x00, 0x84, 0x00, 0x00, 0x81, 0x00, 0x00, 0x80,
0x02, 0x3f, 0xfc, 0x42, 0x20, 0x04, 0x42, 0x3f, 0xf8, 0x44, 0x7f, 0xf8, 0xc2, 0x1f, 0xf8, 0x40,
0x02, 0x20, 0x07, 0xc2, 0x20, 0x04, 0x42, 0x20, 0x04, 0x44, 0x40, 0x0c, 0x42, 0x20, 0x04, 0x40,
0x02, 0x20, 0x00, 0x02, 0x20, 0x04, 0x42, 0x20, 0x04, 0x44, 0x40, 0x04, 0x42, 0x20, 0x04, 0x40,
0x02, 0x1f, 0xfe, 0x02, 0x20, 0x04, 0x42, 0x20, 0x04, 0x44, 0x40, 0x04, 0x42, 0x20, 0x04, 0x40,
0x03, 0x00, 0x03, 0x82, 0x20, 0x04, 0x42, 0x20, 0x0c, 0x44, 0x40, 0x08, 0x42, 0x20, 0x04, 0x40,
0x01, 0xc0, 0x00, 0xc2, 0x20, 0x04, 0x42, 0x3f, 0xf0, 0xc4, 0x7f, 0xf0, 0x82, 0x3f, 0xfc, 0x40,
0x00, 0x7f, 0xf8, 0x42, 0x20, 0x04, 0x42, 0x00, 0x01, 0x84, 0x00, 0x01, 0x82, 0x00, 0x00, 0x40,
0x00, 0x00, 0x04, 0x42, 0x20, 0x04, 0x42, 0x3f, 0xff, 0x04, 0x7f, 0x8e, 0x02, 0x3f, 0xfc, 0x40,
0x03, 0xe0, 0x04, 0x42, 0x20, 0x04, 0x42, 0x20, 0x00, 0x04, 0x40, 0xc6, 0x02, 0x20, 0x04, 0x40,
0x02, 0x3f, 0xfc, 0x42, 0x1f, 0xf8, 0x42, 0x20, 0x00, 0x04, 0x40, 0x63, 0x02, 0x20, 0x04, 0x40,
0x01, 0x00, 0x00, 0x41, 0x00, 0x00, 0x82, 0x20, 0x00, 0x04, 0x40, 0x31, 0x82, 0x20, 0x04, 0x40,
0x00, 0xc0, 0x01, 0x80, 0xc0, 0x03, 0x02, 0x20, 0x00, 0x04, 0x40, 0x18, 0xc2, 0x20, 0x04, 0x40,
0x00, 0x3f, 0xfe, 0x00, 0x3f, 0xfc, 0x03, 0xe0, 0x00, 0x07, 0xc0, 0x0f, 0xc3, 0xe0, 0x07, 0xc0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'Lambda_logo', 32x32px
const unsigned char lambda_logo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00,
0x00, 0xfe, 0x00, 0x00, 0x01, 0xce, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x03, 0x80, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x0f, 0xe0, 0x00,
0x00, 0x0e, 0xe0, 0x00, 0x00, 0x1e, 0xf0, 0x00, 0x00, 0x1c, 0x70, 0x00, 0x00, 0x38, 0x38, 0x00,
0x00, 0x78, 0x3c, 0x60, 0x00, 0x70, 0x1d, 0xe0, 0x00, 0xf0, 0x1f, 0xc0, 0x00, 0xe0, 0x0f, 0xc0,
0x00, 0x60, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'Oeltemp_logo', 32x32px
const unsigned char oeltemp_logo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00,
0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00,
0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x70,
0xfe, 0x18, 0x01, 0x8c, 0x83, 0x9a, 0x06, 0x0c, 0x80, 0xdb, 0x98, 0x30, 0x7c, 0x18, 0x70, 0xc0,
0x04, 0x18, 0x03, 0x00, 0x04, 0x18, 0x06, 0x08, 0x04, 0x7e, 0x0c, 0x08, 0x04, 0x7e, 0x18, 0x1c,
0x04, 0x7e, 0x10, 0x1c, 0x04, 0x3c, 0x10, 0x00, 0x04, 0x00, 0x10, 0x00, 0x03, 0xff, 0xe0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'Wassertemp_logo', 32x32px
const unsigned char wassertemp_logo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x03, 0xc0, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x03, 0xc0, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x03, 0xc0, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
0x18, 0x4f, 0xd0, 0xc2, 0x24, 0x8f, 0xc9, 0x24, 0x43, 0x0f, 0xc6, 0x18, 0x00, 0x07, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x61, 0x86, 0x18, 0x24, 0x92, 0x49, 0x24,
0x43, 0x0c, 0x30, 0xc2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'boost_logo', 32x32px
const unsigned char boost_logo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xc0, 0x00, 0x7f, 0xff, 0xce, 0x01, 0x81, 0x80, 0x40, 0x06, 0x00, 0x60, 0x58,
0x08, 0x00, 0x10, 0x40, 0x10, 0x00, 0x10, 0x4e, 0x10, 0x00, 0x0f, 0xc0, 0x20, 0x3c, 0x04, 0xc0,
0x20, 0x42, 0x04, 0x00, 0x40, 0xc3, 0x02, 0x00, 0x41, 0x24, 0x82, 0x00, 0x41, 0x18, 0x82, 0x00,
0x41, 0x18, 0x82, 0x00, 0x41, 0x24, 0x82, 0x00, 0x40, 0xc3, 0x02, 0x00, 0x20, 0x42, 0x04, 0x00,
0x20, 0x3c, 0x04, 0x00, 0x10, 0x00, 0x08, 0x00, 0x10, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00,
0x02, 0x00, 0x60, 0x00, 0x01, 0x81, 0x80, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'boost_logo', 32x32px
const unsigned char oeldruck_logo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x30, 0x7e, 0x00, 0x00, 0x48, 0x18, 0x00, 0x78,
0x84, 0x18, 0x01, 0xac, 0x43, 0xff, 0x86, 0x64, 0x24, 0x00, 0x58, 0xc0, 0x1c, 0x00, 0x31, 0x80,
0x04, 0x00, 0x03, 0x00, 0x04, 0x00, 0x06, 0x08, 0x04, 0x00, 0x0c, 0x08, 0x04, 0x00, 0x18, 0x1c,
0x04, 0x00, 0x10, 0x1c, 0x04, 0x00, 0x30, 0x08, 0x04, 0x00, 0x20, 0x00, 0x03, 0xff, 0xe0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup () {
Serial.begin(115200);
pinMode(A0, INPUT); //Analogeingang für Wassertemp (Widerstandswert)
pinMode(A1, INPUT); //Analogeingang für Oeltemp (Widerstandswert)
pinMode(A2, INPUT); //Analogeingang für Lambda (Analogwert)
pinMode(WARNTON, OUTPUT); //Ausgabepin für Buzzer
pinMode(NXT_SCRN_BUTTON, INPUT_PULLUP); //Screenschalter nächster Bildschirm
pinMode(PRVS_SCRN_BUTTON, INPUT_PULLUP); //Screenschalter vorheriger Bildschirm
pinMode(HOME_SCRN_BUTTON, INPUT_PULLUP); //Screenschalter Home-Bildschirm (Uhrzeit)
u8g.setFont(u8g_font_fub25);
u8g.setColorIndex(1);
bootscreen();
delay(1000); // Anzeigezeit des Bootlogos
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
}
static int menu = 0; // Button Menu
const float BETA = 3950; //B-Wert für Umrechnung der Tempanzeigen, sollte zum Beta Koeffizienten des NTC-Sensors passen
const int wert_set_Y_pos = 30; //Y-Position der Werte in Pixel von Unterbildschirmen
//****************************************************
// BOOTSCREEN
//****************************************************
void bootscreen(void) {
u8g.firstPage();
do {
u8g.setFont(u8g_font_fub25);
u8g.drawBitmapP(0, 0, 128/8, 32, boot_supra_logo);
} while (u8g.nextPage() );
}
//****************************************************
// LAMBDA
//****************************************************
// Umrechnung Analogwert auf AFR Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float lambda() {
int lambda_sensor = analogRead(A2);
float lambda_wert = lambda_sensor * (10.0 / 1023.0) + 9; // Umrechnung Analogwert auf AFR
//Serial.println(lambda_wert);
u8g.firstPage();
do {
u8g.setFont(u8g_font_fub25);
u8g.drawBitmapP(0, 0, 32/8, 32, lambda_logo);
u8g.setPrintPos(35, wert_set_Y_pos);
u8g.print(lambda_wert);
} while (u8g.nextPage() );
delay(10);
}
//****************************************************
// WASSERTEMP
//****************************************************
void wassertemp() {
int wasser_sensor = analogRead(A0);
int wasser_wert = 1 / (log(1 / (1023. / wasser_sensor - 1)) / BETA + 1.0 / 298.15) - 273.15; // Umrechnung Analogwert auf Wassertemp
u8g.firstPage();
do {
u8g.setFont(u8g_font_fub25);
u8g.drawBitmapP(0, 0, 32/8, 32, wassertemp_logo);
u8g.setPrintPos(40, wert_set_Y_pos);
u8g.print(wasser_wert);
u8g.setPrintPos(95, wert_set_Y_pos);
u8g.println("C");
} while (u8g.nextPage() );
delay(10);
}
//****************************************************
// OELTEMP
//****************************************************
void oeltemp() {
int oel_sensor = analogRead(A1);
int oel_wert = 1 / (log(1 / (1023. / oel_sensor - 1)) / BETA + 1.0 / 298.15) - 273.15; // Umrechnung Analogwert auf Oeltemp
u8g.firstPage();
do {
u8g.setFont(u8g_font_fub25);
u8g.drawBitmapP(0, 0, 32/8, 32, oeltemp_logo);
u8g.setPrintPos(40, wert_set_Y_pos);
u8g.print(oel_wert);
u8g.setPrintPos(95, wert_set_Y_pos);
u8g.println("C");
} while (u8g.nextPage() );
delay(10);
}
//****************************************************
// OELDRUCK
//****************************************************
void oeldruck() {
int oeldruck_sensor = analogRead(A1);
int oeldruck_wert = 1 / (log(1 / (1023. / oeldruck_sensor - 1)) / BETA + 1.0 / 298.15) - 273.15; // Umrechnung Analogwert auf Oeltemp
u8g.firstPage();
do {
u8g.setFont(u8g_font_fub25);
u8g.drawBitmapP(0, 0, 32/8, 32, oeldruck_logo);
u8g.setPrintPos(40, wert_set_Y_pos);
u8g.print(oeldruck_wert);
u8g.setPrintPos(95, wert_set_Y_pos);
u8g.println("C");
} while (u8g.nextPage() );
delay(10);
}
//****************************************************
// LADEDRUCK
//****************************************************
float ladedruck() {
int ladedruck_sensor = analogRead(A2);
float ladedruck_wert = ladedruck_sensor * (10.0 / 1023.0) + 9; // !!! To Do: Umrechnung Analogwert auf Ladedruck in bar !!!
u8g.firstPage();
do {
u8g.setFont(u8g_font_fub25);
u8g.drawBitmapP(0, 0, 32/8, 32, boost_logo);
u8g.setPrintPos(35, wert_set_Y_pos);
u8g.print(ladedruck_wert);
} while (u8g.nextPage() );
delay(10);
}
//****************************************************
// UHRZEIT
//****************************************************
void uhrzeit() { //Screen für Uhrzeit
DateTime now = rtc.now();
int hour = now.hour(); //holt Stunde
int minute = now.minute(); //holt Minute
char stunde[2];
char minute2[2];
sprintf (stunde, "%02d", hour);
sprintf (minute2, "%02d", minute);
u8g.firstPage();
do {
u8g.drawStr(10, wert_set_Y_pos, stunde);
u8g.drawStr(55, wert_set_Y_pos, ":");
u8g.drawStr(75, wert_set_Y_pos, minute2);
} while ( u8g.nextPage() );
}
//****************************************************
// BUTTON MENU
//****************************************************
//int lastState = LOW;
void updatemenu() {
switch (menu) {
case 0:
menu = 1;
break;
case 1: //Uhrzeit
uhrzeit();
break;
case 2: //Lambda
lambda();
break;
case 3: //WASSERTEMP
wassertemp();
break;
case 4: //OELTEMP
oeltemp();
break;
case 5: //OELDRUCK
oeldruck();
break;
case 6: //LADEDRUCK
ladedruck();
break;
case 7:
menu = 1;
break;
}
}
//****************************************************
// PROGRAMM
//****************************************************
void loop() {
if (analogRead(A2) >= 716) //Anstelle des direkten AFR Wertes wir der analoge Eingangswert überwacht. So wird sichergestellt, dass im Hintergrund der Wert weiterhin erfasst wird. 716 entspricht einem AFR von 16
{
// tone(WARNTON, 500);
// delay(50);
// noTone(WARNTON);
// delay(50);
for (byte i = 0; i < 10; i++) {
for (int pitch = -10; pitch <= 10; pitch++) {
tone(WARNTON, NOTE_C5 + pitch);
delay(5);
}
}
noTone(WARNTON);
delay(1);
}
updatemenu();
if (!digitalRead(NXT_SCRN_BUTTON)){
menu++;
updatemenu();
delay(40);
while (!digitalRead(NXT_SCRN_BUTTON));
}
if (!digitalRead(PRVS_SCRN_BUTTON)){
menu--;
updatemenu();
delay(40);
while (!digitalRead(PRVS_SCRN_BUTTON));
}
if (!digitalRead(HOME_SCRN_BUTTON)){
menu=1;
updatemenu();
delay(40);
while (!digitalRead(HOME_SCRN_BUTTON));
}
}
//*********************
// BACKUP
//*********************