#include <WiFi.h>
#include "ELMduino.h"
#include <LiquidCrystal_I2C.h>
#include <RBD_Timer.h>
#include <RBD_Button.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const char* ssid = "WiFi_OBDII";
//IP Adress of your ELM327 Dongle
IPAddress server(192, 168, 0, 10);
// WiFiClient client;
// ELM327 myELM327;
int rpm_gauge; // value for the RPM gauge
int voltage_gauge; // value for the VOLTAGE gauge
uint32_t rpm = 0;
uint32_t vol = 0;
char buffer[40];
//#define CHANGE_BUTON_PIN_4 4
RBD::Button button(4);
int button_select_clicked = 0; //only perform action when button is clicked, and wait until another press
int current_screen = 0;
void setup() {
rpm_gauge = 600; // set "random" value for rpm gauge
voltage_gauge = 12; // set "random" value for voltage gauge
lcd.init();
lcd.backlight();
Serial.begin(115200);
// Serial.print("Connecting to ");
// Serial.println(ssid);
// WiFi.mode(WIFI_AP);
// WiFi.begin(ssid);
// while (WiFi.status() != WL_CONNECTED)
// {
// delay(500);
// Serial.print(".");
// }
// Serial.println("");
// Serial.println("Connected to Wifi");
// Serial.println("IP address: ");
// Serial.println(WiFi.localIP());
// if (client.connect(server, 35000))
// Serial.println("connected");
// else
// {
// Serial.println("connection failed");
// while(1);
// }
// myELM327.begin(client, true, 2000);
}
void loop() {
// pinMode(Button, INPUT_PULLUP);
if(button.onPressed()) {
if (current_screen == 0) {
current_screen = 1;
lcd.clear();
}
else if (current_screen == 1) {
current_screen = 2;
}
else {
current_screen = 0;
lcd.clear();
}
}
// if ((digitalRead(Button) == LOW) && (button_select_clicked == 0)) { // select button clicked, jump between screens
// button_select_clicked = 1; // set button to clicked to only perform the action once
// if (current_screen == 0) {
// current_screen = 1;
// lcd.clear();
// } // menu items screen --> screenshots screen
// // else if (current_screen == 1) {
// // current_screen = 2;
// // } // screenshots screen --> qr codes screen
// else {
// current_screen = 0;
// lcd.clear();
// } // qr codes screen --> menu items screen
// }
// if ((digitalRead(Button) == HIGH) && (button_select_clicked == 1)) { // unclick
// button_select_clicked = 0;
// lcd.clear();
// }
if (current_screen == 0) { // MENU SCREEN
int tempRPM = 2000;
rpm = (uint32_t)tempRPM;
Serial.print("RPM: "); Serial.println(rpm);
lcd.setCursor(0,0); // move cursor to top left
sprintf(buffer, "RPM: %4d%", rpm); //
lcd.print(buffer);
}
else if (current_screen == 1) { // SCREENSHOTS SCREEN
int voltage = 13;
vol = (uint32_t)voltage;
lcd.setCursor(0,1); // move cursor to top left
sprintf(buffer, "Voltage:%2d%", vol); //
lcd.print(buffer);
}
}