#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int potPin = 34;
void setup() {
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display();
display.clearDisplay();
}
void loop() {
int potValue = analogRead(potPin);
float voltage = (potValue / 4095.0) * 3.3;
Serial.print("Nilai Potensiometer: ");
Serial.println(potValue);
Serial.print("Tegangan (V): ");
Serial.println(voltage, 2);
float temperature = (voltage * 100) + 25; // Konversi 10mV per derajat, offset 25 derajat
displayTemperature(temperature);
Serial.print("Suhu (C): ");
Serial.println(temperature, 1);
delay(1000);
}
void displayTemperature(float temperature) {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.println("Suhu:");
display.setTextSize(3);
display.setCursor(0, 30);
display.println(temperature, 1);
display.setTextSize(2);
display.setCursor(80, 30);
display.println("C");
display.display();
}