// Define the pin for the potentiometer and LDR
const int potentiometerPin = A0;
const int ldrPin = A1;

unsigned long previousMillis = 0;
const long interval = 1000; // 1 second interval

void setup() {
  // Start serial communication
  Serial.begin(9600);
}

void loop() {
  unsigned long currentMillis = millis();

  // Check if it's time to read and display values
  if (currentMillis - previousMillis >= interval) {
    // Save the last time you read the values
    previousMillis = currentMillis;

    // Read the value of the potentiometer (0-1023)
    int potValue = analogRead(potentiometerPin);

    // Map the potentiometer value to a range of 1 to 200
    int sensitivity = map(potValue, 0, 1023, 200, 1); // Ensure sensitivity is at least 1

    // Read the value of the LDR
    int ldrValue = analogRead(ldrPin);

    // Calculate the adjusted LDR value as a percentage
    float adjustedLDRValue = (float)ldrValue / sensitivity * 100.0;

    // Print the values to the serial monitor
    Serial.print("Potentiometer Value: ");
    Serial.print(potValue);
    Serial.print("\t Sensitivity (Mapped): ");
    Serial.print(sensitivity);
    Serial.print("\t Raw LDR Value: ");
    Serial.print(ldrValue);
    Serial.print("\t Adjusted LDR Value (%): ");
    Serial.println(adjustedLDRValue);
  }
}