Hello,
First I am new to the forum, new to Arduino, and new to any sort of coding. So forgive me if this ends up being a very simple/obvious answer.
I am currently attempting to have 2 LEDs lit, each with a different brightness. I am using an Arduino Mega2560. Code as follows:
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
analogWrite(13, 15);
pinMode(12, OUTPUT);
analogWrite(12, 100);
}
void loop() {
// put your main code here, to run repeatedly:
}
This results in the LED connected to pin 13 blinking (long, short, short) over a period approx. 1s. and LED connected to 12 not on at all. If I change the code to:
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
analogWrite(13, 100);
pinMode(12, OUTPUT);
analogWrite(12, 100);
}
void loop() {
// put your main code here, to run repeatedly:
}
Both LEDs will turn on and be at the correct dimness.
Any ideas why I cant seem to have the two LEDs display different intensities?
Did you test that.
I can't get it to work no matter what I do.
Only if I write 0 or 255 or the same value to the second PWM pin.
The attached sketch flashes the build-in LED.
Leo..
Wawa:
Did you test that.
I can't get it to work no matter what I do.
Only if I write 0 or 255 or the same value to the second PWM pin.
The attached sketch flashes the build-in LED.
Leo..
bwp723:
This results in the LED connected to pin 13 blinking (long, short, short) over a period approx. 1s. and LED connected to 12 not on at all. If I change the code to:
Sounds like LEDS have no current limit resistors and the load current is causing the Mega to reset..reset..reset.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Tom...
I would guess that there is a bug in the PWM implementation. Pin13 can be connected to either OC0A or OC1C (probably the latter), whereas Pin12 is connected to OC1B.
Unanticipated behaviors occur when an output compare register is changed at the wrong time. I don't have a 2560 to test, but try removing the analogWrite() to pin 12 and see it that changes the behavior.