const float Vled = 2.0; // ________________________________________________
const float Vmax = 3.3; // ________________________________________________
const int PWMmax = 255; // ________________________________________________
int pwmLimit;
void setup() { // ________________________________________
Serial.begin(115200); // ________________________________________
analogReadResolution(10); // ________________________________________
pwmLimit = (Vled / Vmax) * PWMmax;
}
void loop() {
int raw = analogRead(26); // ________________________________________
int pwmValue = map(raw, 0, 1023, pwmLimit, 255); // ____________________________
analogWrite(22, pwmValue); // ________________________________________
Serial.print("ADC: ");
Serial.print(raw);
Serial.print(", PWM: ");
Serial.print(pwmValue);
Serial.print(" (");
Serial.print(pwmLimit);
Serial.print("), Vout: ");
Serial.print((float)pwmValue / 255.0 * 3.3); // ___________________________
Serial.print(" (Vled :");
Serial.print(Vled);
Serial.println(")");
delay(200); // ________________________________________
}