I am having a problem with an Arduino Mega 2560.
Everything works fine, the ultrasonic sensors work fine, and the other LEDs work fine. Although there is 2 LEDs who do not work right and when I do analogWrite()
, they actually do digitalWrite()
. I have tried to attach these two LEDs to a potentiometer (potentiometer works fine, values are tested) but it always does digitalWrite()
not analogWrite()
.
I have tested the LEDs and potentiometer on an Arduino Uno in PWM pins and analog pin and yes it does work very well.
Please mind that these LEDs are attached to analog pins. Why is this? Because I do not have anymore PWM pins available to use and so I have to use analog pins. No way I can rearrange this.
Here is part of the code (only part otherwise it's too long, most of my pins are taken):
//Leds//
int led = A4;
int ledUV = A3;
//Potentiometer//
int potReading;
int potPin = A2;
int lightDim;
void setup(){
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(ledUV, OUTPUT);
pinMode(potPin, INPUT);
}
void loop(){
potReading = analogRead(potPin);
lightDim = (255./1023.)*potReading;
analogWrite(led, lightDim);
// analogWrite(ledUV, lightDim);
// Serial.println("pot: ");
// Serial.println(potReading);
// Serial.println(" ");
Serial.println("dim: ");
Serial.println(lightDim);
// analogWrite(led, 255);
// analogWrite(ledUV, 255);
}