// https://wokwi.com/projects/325823869648634450
//Thermometer with thermistor
//https://create.arduino.cc/projecthub/Marcazzan_M/how-easy-is-it-to-use-a-thermistor-e39321
/*thermistor parameters:
RT0: 10 000 Ω
B: 3977 K +- 0.75%
T0: 25 C
+- 5%
LCD 6p
obd 5p
takkar 2p
relay 2p
*/
#include <LiquidCrystal.h>
#include "OneButton.h" //we need the OneButton library
#include <EEPROM.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//inn og utgangar
//oled er fast á SDA/SCL I2C samskipti
#define BUTTON_PIN 10 //AC takki
#define BUTTON_PIN2 9 //3D takki
#define TVonOUT 12 //TVon relay
#define RCAOUT 11 //RCA out relay
#define CfrontPIN A0 //hitanemi framan
#define CrearPIN A1 //hitanemi aftan
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Dodge logo
const unsigned char myBitmap [] PROGMEM =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x78, 0x00, 0x00, 0x1f, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x01, 0xff, 0x00, 0x00, 0xff, 0xc0, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x07, 0xff, 0x80, 0x01, 0xff, 0xe0, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x0f, 0xff, 0xe0, 0x07, 0xff, 0xf0, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x1f, 0xff, 0xf0, 0x0f, 0xff, 0xf8, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x10, 0x7f, 0xfc, 0x3f, 0xfe, 0x08, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x1f, 0xfe, 0x7f, 0xf8, 0x60, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x1f, 0x8f, 0xfe, 0x7f, 0xf1, 0xf8, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x3f, 0xc7, 0xfe, 0x7f, 0xe3, 0xfc, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x7f, 0xe3, 0xfe, 0x7f, 0xc7, 0xfe, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x7f, 0xf1, 0xfe, 0x7f, 0x8f, 0xfe, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x7f, 0xf0, 0xfe, 0x7f, 0x0f, 0xff, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0xff, 0xf8, 0x7c, 0x3e, 0x1f, 0xff, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0xff, 0xf8, 0x3c, 0x3c, 0x1f, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0xff, 0xfc, 0x1c, 0x38, 0x3f, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0xff, 0xbc, 0x08, 0x10, 0x3d, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x30, 0x7f, 0x3e, 0x00, 0x00, 0x7c, 0xfe, 0x0c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0xbf, 0x3e, 0x00, 0x00, 0x7c, 0xfd, 0x8c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0xbf, 0x3f, 0x80, 0x01, 0xfc, 0xfd, 0x8c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0xdf, 0x3f, 0x00, 0x00, 0xfc, 0xf9, 0x8c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0xdf, 0x1f, 0x00, 0x00, 0xf8, 0xfb, 0x8c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0xdf, 0x07, 0x80, 0x00, 0xe0, 0xfb, 0x8c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0xcf, 0x83, 0x80, 0x01, 0xc0, 0xf3, 0x8c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0xef, 0x83, 0xc0, 0x03, 0xc1, 0xf7, 0x8c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0xe7, 0x83, 0xf0, 0x0f, 0xc1, 0xe7, 0x8c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0xf7, 0x83, 0x90, 0x09, 0xc1, 0xef, 0x8c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x30, 0xfb, 0x81, 0xe0, 0x07, 0x81, 0xdf, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x30, 0xf9, 0xc1, 0xf0, 0x0f, 0x81, 0x9f, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x38, 0x7c, 0x01, 0xf0, 0x0f, 0x80, 0x3e, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x38, 0x7e, 0x00, 0xf0, 0x1f, 0x80, 0x7e, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x38, 0x3f, 0x00, 0xf8, 0x1f, 0x00, 0xfc, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x1f, 0x80, 0x78, 0x1e, 0x00, 0xf8, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x1f, 0xc0, 0x38, 0x1c, 0x03, 0xf8, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x03, 0xc0, 0x38, 0x1c, 0x01, 0xc0, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x1e, 0x78, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0f, 0x70, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x05, 0xe0, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x07, 0xe0, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// onebuttons
OneButton button = OneButton(
BUTTON_PIN, // Input pin for the button
true, // Button is active LOW
true // Enable internal pull-up resistor
);
OneButton button2 = OneButton(
BUTTON_PIN2, // Input pin for the button
true, // Button is active LOW
true // Enable internal pull-up resistor
);
// Hitanemi frumgildi
#define RT0 10000 // Ω
#define B 3977 // K breytingargildið
#define VCC 5 //Supply voltage
#define R 10000 //R=10KΩ
float RT, VR, ln, TX, T0, VRT;
int TX2;
float RTr, VRr, lnr, TXr, T0r, VRTr;
int TX2r;
//--------------------------------------
// Hitistýring breytur
int ACauto = 0;
int ACstatus = 0;
int CIRCstatus = 0; //inni eda utiloft
int REARstatus = 0;
unsigned int ACpsi;
int NEMIfront;
int NEMIrear;
int programmode = 0;
String ACpsitmp;
unsigned long ACpreviousMillis = 0;
const long ACinterval = 2000; // uppfæri ac tölur á 3sek fresti
int prstep = 1;
int frontlow, fronthigh, rearlow, rearhigh;
int updown;
String incomingString;
String incomingString2;
String incomingString3;
//3D breytur
int TVon = 0;
int SPon = 0;
int bida = 0;
int eprom;
int REVon = 0;
unsigned long previousMillis = 0;
const long interval = 4000; //60000; //timi on eftir click
// Almennar bretur
int startup = 0;
#define ON 1
#define OFF 0
int serial = true;
// dev breytur
void setup() {
// Frumstilli oled ath adressu 3C i raun
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // 3C i raun
//Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Syna logo on oled
display.clearDisplay();
display.drawBitmap(0, 0, myBitmap, 128, 64, SSD1306_WHITE);
display.display();
delay(1000);
// Frumstilli serial obd
/*
TX0 and RX0 are Serial.write();
TX1 and RX1 is Serial1.write();
TX2 and RX2 is Serial2.write();
TX3 and RX3 is Serial3.write();
*/
Serial.begin(9600);
Serial.setTimeout(90); //testa
// Frumstilli obd
Serial.println("ATAT0"); // testa
delay(500);
Serial.println("ATST01"); // testa
delay(500);
Serial.println("ATL1");
delay(500);
Serial.println("ATH1");
delay(500);
Serial.println("ATS1");
delay(500);
Serial.println("ATAL");
delay(500);
Serial.println("ATMA");
delay(500);
Serial.read(); // hreinsa rusl
delay(500);
Serial.readStringUntil('\n'); // hreinsa
//dev
pinMode(LED_BUILTIN, OUTPUT);
// Takkar
button.attachDoubleClick(doubleclick); // link the function to be called on a doubleclick event.
button.attachClick(singleclick); // link the function to be called on a singleclick event.
button.attachLongPressStop(longclick); // link the function to be called on a longpress event.
button2.attachDoubleClick(doubleclick2); // link the function to be called on a doubleclick event.
button2.attachClick(singleclick2); // link the function to be called on a singleclick event.
button2.attachLongPressStop(longclick2); // link the function to be called on a longpress event.
//Hitanemi frumstilli
T0 = 25 + 273.15; //Temperature T0 from datasheet, conversion from Celsius to kelvin
T0r = 25 + 273.15;
//25c samkvæmt mælinum var 297.28K ohm, skoða það
// 3D
eprom = EEPROM.read(0);
//Serial.print("eprom boot:");
//Serial.println(eprom);
pinMode(RCAOUT, OUTPUT);
pinMode(TVonOUT, OUTPUT);
//digitalWrite(8, OFF);
digitalWrite(RCAOUT, OFF);
digitalWrite(TVonOUT, OFF);
if (eprom == 1) {
digitalWrite(RCAOUT, ON);
}
if (eprom == 255) { eprom = 0;}
// AC stilligildi
frontlow = EEPROM.read(1);
fronthigh = EEPROM.read(2);
rearlow = EEPROM.read(3);
rearhigh = EEPROM.read(4);
// tmp vegna profana
if (frontlow == 255) {frontlow = 17;}
if (fronthigh == 255) {fronthigh = 27;}
if (rearlow == 255) {rearlow = 17;}
if (rearhigh == 255) {rearhigh = 27;}
//ACpsi = 71;
}
//-------------------------------------------LOOP-------------------------------------------------------------------------
void loop() {
if (programmode == 0) {
// uppfaeri hita a x sec fresti
unsigned long ACcurrentMillis = millis();
if (ACcurrentMillis - ACpreviousMillis >= ACinterval or startup == 0) {
ACpreviousMillis = ACcurrentMillis;
startup = 1;
// hitanemi framan
VRT = analogRead(CfrontPIN); //Acquisition analog value of VRT
VRT = (5.00 / 1023.00) * VRT; //Conversion to voltage
VR = VCC - VRT;
RT = VRT / (VR / R); //Resistance of RT
ln = log(RT / RT0);
TX = (1 / ((ln / B) + (1 / T0))); //Temperature from thermistor
TX = TX - 273.15; //Conversion to Celsius
TX2 = round(TX);
//* 2;
//TX2 = round(TX2);
//TX2 = TX2 / 2;
//hitanemi aftan
VRTr = analogRead(CrearPIN); //Acquisition analog value of VRT
VRTr = (5.00 / 1023.00) * VRTr; //Conversion to voltage
VRr = VCC - VRTr;
RTr = VRTr / (VRr / R); //Resistance of RT
lnr = log(RTr / RT0);
TXr = (1 / ((lnr / B) + (1 / T0r))); //Temperature from thermistor
TXr = TXr - 273.15; //Conversion to Celsius
TX2r = round(TXr);
//TX2r = TXr * 2;
//TX2r = round(TX2r);
//TX2r = TX2r / 2;
//lcdset();
//oled();
//ath hvort ac er on og hvort rear blower se i gangi
//rear on eda off mismunandi
if (ACauto == 1) {
if (TX2 < frontlow and ACstatus == 1) {
Serial.println(">>>>>>>>>> SLEKK A AC");
ACstatus = 0;
}
if (TX2 > fronthigh and ACstatus == 0) {Serial.println(">>>>>>>>>> KVEIKI A AC"); ACstatus = 1;}
}
}
} else {
// PROGRAMM MODE -------------------------------------
}
button.tick(); // check the status of the button
button2.tick();
if (startup == 0) {
//lcdset();
oled();
startup = 1;
}
unsigned long currentMillis = millis();
if (TVon == 1 && bida == 0) {
previousMillis = currentMillis;
bida = 1;
Serial.println(currentMillis );
Serial.println(previousMillis );
}
if (TVon == 1 && bida == 1) {
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
digitalWrite(TVonOUT, OFF);
digitalWrite(RCAOUT, eprom);
TVon = 0;
bida = 0;
}
}
if (Serial.available() > 0) {
/////////////////////////////////////////// OBD LESTUR ////////////////////////
// read the incoming string:
incomingString = Serial.readStringUntil('\n');
// Bakkgir or not 37 02 00 CB -- annar biti 02 er bakkgir
if (incomingString.substring(0,2) == "37") {
if (incomingString.substring(3,5) == "02") { // substring fra til
//Serial.println("OBD BAKK");
REVon = 1;
} else {
//Serial.println("OBD EKKI BAKK");
REVon = 0;
}
}
// AC psi (D2 66 48 27 00 C1 -- fjordi biti x 2.03)
else if (incomingString.substring(0,2) == "D2") {
ACpsitmp = incomingString.substring(9,11);
unsigned int x = hexToDec(ACpsitmp);
ACpsi = x * 2.03;
}
// AC on/off 52 18 5D <DATA ERROR
else if (incomingString.substring(0,2) == "52") {
}
if (ACpsi > 300){
// ef ac er on slekk eg og set BILUN í stað auto/manual
}
// serial sending, notað við prófanir
// prints the received data
//Serial.print("I received: ");
//Serial.println(incomingString);
if (incomingString == "ac") {
if (ACstatus == 0) {
ACstatus = 1;
digitalWrite(LED_BUILTIN, HIGH);
} else {
ACstatus= 0;
digitalWrite(LED_BUILTIN, LOW);
}
}
else if (incomingString == "rev") {
if (REVon == 1) {
REVon = 0;
Serial.println("EKKI BAKKGIR");
} else {
REVon = 1;
Serial.println("BAKKA");
}
}
else if (incomingString.indexOf("psi") >= 0) {
incomingString.substring(2);
Serial.println( incomingString.substring(4));
//ACpsitmp = incomingString.substring(4);
//ACpsi = ACpsitmp.toInt();
oled();
}
else if (incomingString == "program") {
if (programmode == 1) {
programmode = 0;
} else {
programmode = 1;
}
}
}
oled();
//delay(10);
}
//-------------------------------------------FUNC-------------------------------------------------------------------------
// ac AUTO EÐA MANUAL
void singleclick() { // what happens when the button is clicked
//Serial.println("singleclick");
if (programmode == 0) {
if (ACauto == 1) {
ACauto = 0;
} else {
ACauto = 1;
}
//PROGRAM MODE
} else {
updown = -1;
setgildi();
}
}
//
void doubleclick() {
//Serial.println("dobleclick");
if (programmode == 1) {
updown = 1;
setgildi();
}
}
// fer gegnum step i programming mode
void setgildi() {
if (prstep == 1) {
Serial.println(prstep);
frontlow = frontlow + updown;
//lcd.setCursor(5, 1);
//lcd.print(frontlow);
EEPROM.update(1, frontlow);
} else if (prstep == 2) {
fronthigh = fronthigh + updown;
//lcd.setCursor(5, 1);
//lcd.print(fronthigh);
EEPROM.update(2, fronthigh);
} else if (prstep == 3) {
rearlow = rearlow + updown;
//lcd.setCursor(5, 1);
//lcd.print(rearlow);
EEPROM.update(3, rearlow);
} else if (prstep == 4) {
rearhigh = rearhigh + updown;
//lcd.setCursor(5, 1);
//lcd.print(rearhigh);
EEPROM.update(4, rearhigh);
}
}
void longclick() { // what happens when buton is long-pressed
//Serial.println("longclick");
if (programmode == 1 ) {
if (prstep > 3) {
programmode = 0;
Serial.println("NORMAL!MODE");
Serial.println(frontlow);
Serial.println(fronthigh);
Serial.println(rearlow);
Serial.println(rearhigh);
//lcdset();
} else {
prstep = prstep + 1;
}
} else {
programmode = 1;
Serial.println("PROGRAM!MODE");
prstep = 1;
}
//lcdset();
}
void singleclick2() { // what happens when the button is clicked
Serial.println("singleclick2");
if (TVon == 0) {
if (eprom == 0) {
if (REVon == 0) {
digitalWrite(RCAOUT, ON);
}
}
TVon = 1;
digitalWrite(TVonOUT, ON);
} else {
// SLOKKVA
TVon = 0;
bida = 0;
digitalWrite(TVonOUT, OFF);
digitalWrite(RCAOUT, eprom);
}
}
void doubleclick2() {
Serial.println("dobleclick2");
if (TVon == 0) {
if (eprom == 0) {
if (REVon == 0) {
digitalWrite(RCAOUT, ON);
}
}
TVon = 2;
digitalWrite(TVonOUT, ON);
bida = 0;
} else {
}
}
void longclick2() { // what happens when buton is long-pressed
Serial.println("longclick2");
if (serial == true) {
Serial.println("longpress2");
}
if (serial == true) {
Serial.print("les eprom: ");
}
if (serial == true) {
Serial.println(eprom);
}
if (eprom == 0) {
eprom = 1;
EEPROM.update(0, 1);
digitalWrite(RCAOUT, ON);
if (serial == true) {
Serial.println("set eprom 1");
}
} else {
eprom = 0;
EEPROM.update(0, 0);
digitalWrite(RCAOUT, OFF);
if (serial == true) {
Serial.println("set eprom 0");
}
}
}
void oled () {
if (incomingString.substring(0,2) == "D2" or incomingString.substring(0,2) == "37") {
display.clearDisplay();
display.setTextColor(SSD1306_WHITE); // Draw white text
/*
display.setCursor(0,0);
display.setTextSize(1);
display.println("FRONT");
display.setCursor(0,8);
display.setTextSize(3);
display.print(TX2);
display.setTextSize(1);
display.println("c");
display.setCursor(0,33);
display.setTextSize(1);
display.println("REAR");
display.setCursor(0,43);
display.setTextSize(3);
display.print(TX2r);
display.setTextSize(1);
display.println("c");
*/
display.setCursor(60,0);
display.setTextSize(1);
display.println("AC PSI");
display.setCursor(60,8);
display.setTextSize(3);
display.print(ACpsi);
display.setCursor(115,0);
display.setTextSize(2);
if (REVon == 1) { display.print("R"); }
display.setTextSize(1);
display.setCursor(0,33);
display.print(incomingString);
display.setCursor(0,43);
display.print(incomingString2);
display.setCursor(0,53);
display.print(incomingString3);
incomingString3 = incomingString2;
incomingString2 = incomingString;
incomingString = "";
Serial.println(incomingString);
Serial.println(incomingString2);
Serial.println(incomingString3);
/*
if (ACpsi > 300){
display.print("ERROR");
//lcd.setCursor(11, 1);
//lcd.print("BILUN");
//lcd.setCursor(9, 0);
// lcd.print(">");
} else {
if (ACauto == 0) {
//lcd.print("MAN");
display.print("MANUAL");
} else {
//lcd.print("AUT");
display.print("AUTO");
}
*/
//}
display.display();
}
}
unsigned int hexToDec(String hexString) {
unsigned int decValue = 0;
int nextInt;
for (int i = 0; i < hexString.length(); i++) {
nextInt = int(hexString.charAt(i));
if (nextInt >= 48 && nextInt <= 57) nextInt = map(nextInt, 48, 57, 0, 9);
if (nextInt >= 65 && nextInt <= 70) nextInt = map(nextInt, 65, 70, 10, 15);
if (nextInt >= 97 && nextInt <= 102) nextInt = map(nextInt, 97, 102, 10, 15);
nextInt = constrain(nextInt, 0, 15);
decValue = (decValue * 16) + nextInt;
}
return decValue;
}
// Converting from Decimal to Hex:
// NOTE: This function can handle a positive decimal value from 0 - 255, and it will pad it
// with 0's (on the left) if it is less than the desired string length.
// For larger/longer values, change "byte" to "unsigned int" or "long" for the decValue parameter.
String decToHex(byte decValue, byte desiredStringLength) {
String hexString = String(decValue, HEX);
while (hexString.length() < desiredStringLength) hexString = "0" + hexString;
return hexString;
}
/*
void lcdset() {
if (programmode == 0) {
lcd.begin(16, 2);
//lcd.print("F:");
lcd.write((byte)0);
lcd.print(TX2);
lcd.print("c");
lcd.setCursor(5, 0);
lcd.print("F:70L");
lcd.setCursor(5, 1);
lcd.print(ACpsi);
lcd.print("psi");
lcd.setCursor(0, 1);
//lcd.print("R:");
lcd.write((byte)1);
lcd.print(TX2r);
lcd.print("c");
lcd.setCursor(13, 1);
if (ACpsi > 300){
lcd.setCursor(11, 1);
lcd.print("BILUN");
lcd.setCursor(9, 0);
// lcd.print(">");
} else {
if (ACauto == 0) {
lcd.print("MAN");
} else {
lcd.print("AUT");
}
}
} else {
lcd.begin(16, 2);
if (prstep == 1) {lcd.print("Front low");}
if (prstep == 2) {lcd.print("Front high");}
if (prstep == 3) {lcd.print("Rear low");}
if (prstep == 4) {lcd.print("Rear high");}
lcd.setCursor(13, 0);
lcd.print(prstep);
lcd.print("/4");
lcd.setCursor(0, 1);
lcd.print("1x < ");
if (prstep == 1) {lcd.print(frontlow);}
if (prstep == 2) {lcd.print(fronthigh);}
if (prstep == 3) {lcd.print(rearlow);}
if (prstep == 4) {lcd.print(rearhigh);}
lcd.print(" > 2x");
}
}
*/