Having the 11~ pin on OUTPUT mode that delivers a varying voltage (from 0 to 5 : 0 to 255).
and the A0 pin on INPUT mode to read the voltage, I find that the value read by A0 being either 0 or 1016 instead of it gradually taking multiple values between the two. what is the catch?
The circuit and the code i am using:
int volt = 0;
int sign = 1; //values: (1, -1), increments or decrements "volt" by 5.
float potential;
void setup() {
pinMode(11, OUTPUT);
pinMode(A0, INPUT);
Serial.begin(9600);
}
void loop() {
if (volt == 0){sign = 1;}
if (volt == 255){sign = -1}
volt = volt + sign * 5; //raises brightness to 255 from 0, then to 0 from 255.
analogWrite(11, volt);
potential = analogRead(A0);
Serial.println(potential);
delay(30);
/*
*/
}