#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Encoder.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define SCREEN_WIDTH 128 // Ancho de la pantalla OLED en píxeles
#define SCREEN_HEIGHT 64 // Altura de la pantalla OLED en píxeles
#define OLED_RESET -1 // El pin de reset del display OLED
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Encoder encoder(2, 3); // CLK a pin 2, DT a pin 3
int encoderPos = 0;
int lastPosition = -999;
int currentPage = 1;
const int totalPages = 2;
unsigned long startTime = 0;
// Define la imagen en forma de array de bytes (bitmap)
const unsigned char PROGMEM imagen[] = {
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x81, 0xfe, 0xff, 0x81, 0xf8, 0xf1, 0xbf, 0xf0, 0x7f, 0xfe, 0x0c, 0xff, 0x87, 0xf8, 0xfe, 0x01,
0x81, 0xfe, 0xff, 0xc3, 0xfc, 0xf9, 0xbf, 0xf0, 0x7f, 0xef, 0x0d, 0xff, 0xc7, 0xf9, 0xff, 0x81,
0x81, 0xc0, 0xe0, 0xe7, 0x86, 0xf9, 0x87, 0x80, 0x07, 0x07, 0x99, 0xe1, 0xc7, 0x01, 0xe0, 0x01,
0x81, 0xfe, 0xff, 0xc7, 0x06, 0xfd, 0x87, 0x80, 0x07, 0x03, 0xf1, 0xff, 0xc7, 0xf9, 0xff, 0x01,
0x81, 0xfe, 0xff, 0x87, 0x06, 0xdf, 0x87, 0x80, 0x07, 0x01, 0xe1, 0xff, 0x87, 0xf8, 0xff, 0x81,
0x81, 0xc0, 0xfc, 0x17, 0x86, 0xcf, 0x87, 0x80, 0x07, 0x01, 0xe1, 0xfc, 0x37, 0x00, 0x07, 0x81,
0x81, 0xc0, 0xef, 0xf3, 0xfc, 0xcf, 0x87, 0x80, 0x07, 0x01, 0xe1, 0xef, 0xf7, 0xf9, 0xc3, 0x81,
0x81, 0xc0, 0xe3, 0xe1, 0xf8, 0xc7, 0x87, 0x80, 0x07, 0x01, 0xe1, 0xe7, 0xe7, 0xfc, 0xff, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
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,
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x3f, 0xe1, 0xff, 0x0f, 0x0f, 0xf8, 0x03, 0xff, 0xf0, 0x6f, 0xfc, 0x3f, 0xc7, 0xf0, 0x01,
0x80, 0x3f, 0xf1, 0xff, 0x1f, 0x0f, 0xfe, 0x03, 0xff, 0x78, 0xef, 0xfe, 0x3f, 0xcf, 0xf8, 0x01,
0x80, 0x38, 0x79, 0xc0, 0x1f, 0x8e, 0x0e, 0x00, 0x38, 0x3c, 0xcf, 0x0e, 0x38, 0x0f, 0x00, 0x01,
0x80, 0x3f, 0xf1, 0xfe, 0x33, 0x8f, 0xfe, 0x00, 0x38, 0x1d, 0x8f, 0xfe, 0x3f, 0xcf, 0xf8, 0x01,
0x80, 0x3f, 0xe1, 0xfe, 0x33, 0xcf, 0xfc, 0x00, 0x38, 0x1f, 0x0f, 0xfc, 0x3f, 0xc7, 0xfc, 0x01,
0x80, 0x3f, 0x05, 0xc0, 0x7f, 0xcf, 0xe1, 0x00, 0x38, 0x0f, 0x0f, 0xe1, 0xb8, 0x00, 0x3c, 0x01,
0x80, 0x3b, 0xfd, 0xff, 0x61, 0xee, 0xff, 0x00, 0x38, 0x0e, 0x0f, 0x7f, 0xbf, 0xce, 0x1c, 0x01,
0x80, 0x39, 0xf9, 0xff, 0x61, 0xee, 0x3e, 0x00, 0x38, 0x0e, 0x0f, 0x3f, 0x3f, 0xc7, 0xf8, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc
// Aquí va la información de la imagen en formato byte
};
// Arreglo de texto para cada página
const char* paginas[] = {
"BRAKE BIAS",
"TEMPERATURA",
"PRESION",
"Página 4",
"Página 5"
};
const int sensorPin = A0; // Pin analógico al que está conectado el sensor de presión
const int sensorPin2 = A1; // Segundo pin analógico al que está conectado el sensor de presión
const int waterTempPin = A3; // Pin analógico al que está conectado el sensor de temperatura de agua
const int oilPressurePin = A4; // Pin analógico al que está conectado el sensor de presión de aceite
const int oilTempPin = A5; // Pin analógico al que está conectado el sensor de temperatura de aceite
const int potPin = 1; // Pin digital al que está conectado el potenciómetro
OneWire oneWire(10); // Pin al que está conectado el sensor de temperatura DS18B20
DallasTemperature sensors(&oneWire);
float tempCelsius;
void mostrarImagenInicial() {
display.clearDisplay();
display.drawBitmap(0, 0, imagen, SCREEN_WIDTH, SCREEN_HEIGHT, WHITE); // Mostrar imagen en página 1
display.display();
}
void mostrarPagina(int pageNumber) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
if (pageNumber != 0) {
display.println(paginas[pageNumber]); // Mostrar el texto de la página
}
if (pageNumber == 0) {
display.drawBitmap(0, 0, imagen, SCREEN_WIDTH, SCREEN_HEIGHT, WHITE); // Mostrar imagen en página 1
int sensorValue = analogRead(sensorPin);
float psiValue = map(sensorValue, 0, 1023, 0, 1000);
display.setTextSize(1.8);
display.setTextColor(SSD1306_WHITE);
display.setCursor(40, 17);
display.print(psiValue);
display.print(" PSI");
int sensorValue2 = analogRead(sensorPin2);
float psiValue2 = map(sensorValue2, 0, 1023, 0, 1000);
display.setCursor(40, 51);
display.print(psiValue2);
display.print(" PSI");
}
if (pageNumber == 1) { // Verificar si es la página 2
// Mostrar los valores de los sensores en la página 2
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
float waterTemp = analogRead(waterTempPin) * 0.488; // Convertir el valor analógico a temperatura en grados Celsius
float oilPressure = analogRead(oilPressurePin) * 0.488; // Convertir el valor analógico a presión en PSI
float oilTemp = analogRead(oilTempPin) * 0.488; // Convertir el valor analógico a temperatura en grados Celsius
display.setTextSize(1.8);
display.setTextColor(SSD1306_WHITE);
display.setCursor(10, 9);
display.print("ASIST PUMP:");
display.print(waterTemp);
display.println(" C");
display.setCursor(10, 29);
display.print("FUEL:");
display.print(oilPressure);
display.println(" PSI");
display.setCursor(10, 49);
display.print("GEARBOX:");
display.print(oilTemp);
display.println(" C");
}
display.display();
}
void setup() {
Serial.begin(9600);
sensors.begin(); // Inicializar el sensor de temperatura
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
display.setTextSize(1); // Tamaño del texto
display.setTextColor(SSD1306_WHITE); // Color del texto
}
void loop() {
// Luego de 5 segundos, mostrar la página actual
mostrarPagina(currentPage);
// Esperar a que el encoder se gire
int newPosition = encoder.read();
if (newPosition != lastPosition) {
// Incrementar o decrementar la página según la dirección del giro del encoder
if (newPosition > lastPosition) {
currentPage = (currentPage + 1) % totalPages;
} else {
currentPage = (currentPage - 1 + totalPages) % totalPages;
}
lastPosition = newPosition;
}
}