Skip to content

Instantly share code, notes, and snippets.

@ff6347
Created October 31, 2022 10:37
Show Gist options
  • Select an option

  • Save ff6347/1d77c4ce343a0342d62da2a4b6267d57 to your computer and use it in GitHub Desktop.

Select an option

Save ff6347/1d77c4ce343a0342d62da2a4b6267d57 to your computer and use it in GitHub Desktop.

Revisions

  1. ff6347 created this gist Oct 31, 2022.
    28 changes: 28 additions & 0 deletions arduino_ldr_calibrate.ino
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    int poti = A0;
    int led = 9;
    int inMax = 0;
    int inMin = 1023;
    void setup() {
    Serial.begin(9600);
    pinMode(led, OUTPUT);
    }

    void loop() {
    int value = analogRead(poti);
    if (inMin > value) {
    inMin = value;
    }
    if (inMax < value) {
    inMax = value;
    }
    int mapped_value = map(value,
    inMin,
    inMax,
    0,
    255);
    // analogWrite(led, mapped_value); // or devide value by 4
    Serial.println(mapped_value);
    // Serial.println(inMin);
    // Serial.println(inMax);
    delay(100);
    }