#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI
int potPin = A1; // Potentiometer connected to A1
int ledPin = 13; // LED connected to digital pin 13 (or choose another pin)
int psi; // Variable to store the turbo PSI value
unsigned long lastToggleTime = 0; // Time when the message was last toggled
bool showMessage = false; // Whether to show the message or not
void setup() {
u8g.setFont(u8g_font_tpssb);
u8g.setColorIndex(1);
pinMode(potPin, INPUT); // Initialize the potentiometer pin as an input
pinMode(ledPin, OUTPUT); // Initialize the LED pin as an output
}
void loop() {
int potValue = analogRead(potPin); // Read the value from the potentiometer
psi = map(potValue, 0, 1023, 0, 20); // Map the potentiometer value to PSI range (0-20)
int progress = map(psi, 0, 20, 0, 108); // Map PSI value to progress bar width
if (millis() - lastToggleTime > 500) { // Toggle every 500 milliseconds
showMessage = !showMessage; // Toggle the visibility of the message
lastToggleTime = millis(); // Update the last toggle time
}
// Control the LED based on PSI value
if (psi > 16) {
digitalWrite(ledPin, HIGH); // Turn the LED on
delay(100); // Wait for 100ms
digitalWrite(ledPin, LOW); // Turn the LED off
}
u8g.firstPage();
do {
// Display "WTF BRO!" or "Turbo Psi:" based on showMessage and PSI value
if (psi >= 16 && showMessage) {
u8g.drawStr(25, 60, "WTF BRO!"); // Display "WTF BRO!"
} else {
u8g.drawStr(25, 60, "Turbo Psi: "); // Display "Turbo Psi:"
u8g.setPrintPos(100, 60);
u8g.print(psi); // Display the PSI value
}
u8g.drawFrame(0, 20, 128, 20);
u8g.drawBox(10, 25, progress, 10);
// Draw scale and numbers
for (int i = 0; i <= 20; i++) {
int x = map(i, 0, 20, 10, 118);
u8g.drawVLine(x, 15, 5);
if (i % 5 == 0) {
u8g.setPrintPos(x-4, 12);
u8g.print(i);
}
}
} while ( u8g.nextPage() );
delay(100); // Add a delay for visual effect
}