/*********
2209106010 - NAVIRA ARDITHA AULIA
2209106018 - ADRIATI MANUK ALLO
2209106020 - AGHNIA NURHIDAYAH
*********/

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <LiquidCrystal_I2C.h>

//Setting OLED
#define I2C_SDA 35
#define I2C_SCL 36

#define SCREEN_WIDTH 128 // Lebar layar OLED dalam piksel
#define SCREEN_HEIGHT 64 // Tinggi layar OLED dalam piksel

#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//---------------------------------- 

// LDR Characteristics
const float GAMMA = 0.7;
const float RL10 = 50;

void setup() {
  Wire.begin(I2C_SDA, I2C_SCL);
  Serial.begin(115200);
  Serial.println("\nI2C Scanner");

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  //hapus OLED
  display.clearDisplay();
  
  //tampilkan ke OLED
  display.display();
  delay(2000);
 
}
 
void loop() {
  int analogValue = analogRead(2);
  float voltage = analogValue / 1024. * 5;
  float resistance = 2000 * voltage / (1 - voltage / 5);
  float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));

  display.clearDisplay();
  display.setTextSize(1);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(0,0);             // Start at top-left corner
  
  display.print("Room: ");
  if (lux > 50) {
    display.print("Light!");
  } else {
    display.print("Dark  ");
  }

  display.setCursor(0, 10);
  display.print("Lux: ");
  display.print(lux);
  display.print("          ");

  display.display();

  delay(100);
}
Loading
esp32-s3-devkitc-1