New user, but I verify on my o-scope that the pot is putting out a variable voltage.
As expected for an Uno, your printing the pin number. You are missing analogRead if you want to read from the potSignal pin.
In future, please post code as described in How to get the best out of this forum.
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project See About the Installation & Troubleshooting category.
I had it commented out in the above attachment (troubleshooting program by parts), but here it is as running, and it has analogRead.
int ledPin=6;
int Bright=180;
int potSignal=A2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode (potSignal, INPUT);
pinMode (ledPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
analogRead(potSignal);
Serial.print("Input is ");
Serial.print(potSignal);
Serial.print(" Output is ");
Serial.println(Bright);
analogWrite(ledPin,Bright);
}
No. You still printing the pin number, not the value that analogRead() returns.
Like
int someVariable = analogRead(somePin);
Serial.println(someVariable);
HTH
a7
You confused yourself by calling it potSignal. call it what it is - potPinNumber and you will see why it doesn’t change
Have a look at the analog example in the IDE , that might help too
Simple but effective way to tell me what is wrong. I want to serial.print the voltage going to the LED. Do I need to tap that signal coming out of 6 and plug it into an input, then read it?
I did change how I called my analogRead, that allows the circuit to work for the first time. Verified by o-scope.
But
That won't work unless you low pass filter the PWM signal which is what analogWrite() puts out.
And low pass filtering for purposes of dimming an LED is def not what you want. Dimming LEDs by PWM is preferred. Which makes noraml analogWrite() just right.
Added: if you want "real" digital to analog conversion, you can use a board/chip that has them build in, or attach an DAC IC or module holding such a chip. You can get SPI and I2C chips and talk to them that way.
a7
Thanks, I'll close the loop for posterity. Between the comments and re-watching McWhorter's chapter 14, I finally got it. You can tell I am an Engineer (MfgE), because I overcomplicated it.
Y'all helped, this was pure wetware error.
int potPin=A2;
int gPin=6;
int potVal;
float LEDVal;
void setup() {
// put your setup code here, to run once:
pinMode(potPin, INPUT);
pinMode(gPin,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
potVal=analogRead(potPin);
LEDVal=potVal*(255./1023.);
analogWrite(gPin,LEDVal);
Serial.print(LEDVal);
Serial.print(" based on ");
Serial.println(potVal);
delay(100);
}
Your
LEDVal=potVal*(255./1023.);
would be neater as
LEDVal=potVal >> 2; //divide by 4
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.