Skip to content

Instantly share code, notes, and snippets.

@ff6347
Created October 31, 2022 10:37
Show Gist options
  • Save ff6347/1d77c4ce343a0342d62da2a4b6267d57 to your computer and use it in GitHub Desktop.
Save ff6347/1d77c4ce343a0342d62da2a4b6267d57 to your computer and use it in GitHub Desktop.
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment