/*
https://forum.arduino.cc/t/led-statusanzeige/1313161
Potentiometer auslesen und LEDs einschalten
*/
constexpr uint8_t redPin {32};
constexpr uint8_t yelAPin {33};
constexpr uint8_t yelBPin {25};
constexpr uint8_t greAPin {14};
constexpr uint8_t greBPin {12};
constexpr uint8_t greCPin {13};
constexpr uint8_t potPin {34};
constexpr uint8_t outPin[] {redPin, yelAPin, yelBPin, greAPin, greBPin, greCPin};
void readPot() {
//in
int potValue = analogRead(potPin);
Serial.print("potValue="); Serial.println(potValue);
// map to 0..100
int mapped = map(potValue, 0, 4096, 0, 100);
Serial.print("mapped="); Serial.println(mapped);
// out
for (auto &i : outPin) digitalWrite(i, LOW); // switch off all
// separate ifs in case the scale isn't linear
if (mapped > 0)
digitalWrite(outPin[0], HIGH);
if (mapped > 15)
digitalWrite(outPin[1], HIGH);
if (mapped > 30)
digitalWrite(outPin[2], HIGH);
if (mapped > 45)
digitalWrite(outPin[3], HIGH);
if (mapped > 60)
digitalWrite(outPin[4], HIGH);
if (mapped > 90)
digitalWrite(outPin[5], HIGH);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
for (auto &i : outPin) pinMode(i, OUTPUT);
}
void loop() {
readPot();
delay(10); // this is only needed in this simulator
}
//